1,A. Long Comparison-Educational Codeforces Round 118 (Rated for Div. 2)
Meaning: give x1,y1,x2,y2. X1 and X2 represent the cardinality, y1 and y2 represent the power of multiplying by 10 (for example, x1=29,y1=3, the number is 29000). It is required to judge whether X1 times 10 is greater to the y1 power or x2 times 10 is greater to the y2 power.
Problem solution: first judge the sizes of x1.size()+n and x2.size()+m. if the former is large, output the greater than sign; if the latter is large, output the less than sign. If they are equal, perform the following operations. k=max(x1.size(), x2.size()), then add zero after the smaller string to make it the same length, and then compare the size from the first number. If the size is the same at the end of the comparison, directly output the equal sign.
Explanation: y1 and y2 are the 6th power of 10. It's too slow to complete the whole string. First, it's easy to judge the number of digits. After that, you start to judge. Because the following zeros are meaningless, you only compare the numbers entered earlier.
code:
#include<iostream> #include<string> using namespace std; string x,y; int main() { int t; cin >> t; int n,m; while(t--) { cin >> x>>n; cin>>y>>m; if(x.size()+n>y.size()+m) cout<<'>'<<endl; else if(x.size()+n<y.size()+m) cout<<'<'<<endl; else { int z=max(x.size(),y.size()); for(int i1=0;i1<z;i1++) { if(x.size()<=z-1) x+='0'; else if(y.size()<=z-1) y+='0'; if(x[i1]>y[i1]) {cout<<'>'<<endl;break;} else if(x[i1]<y[i1]) {cout<<'<'<<endl;break;} else if(i1==z-1) cout<<'='<<endl; } } } return 0; }
2,B. Absent Remainder-Educational Codeforces Round 118 (Rated for Div. 2)
Given an array a containing N integers, it is required that any x, y belong to a and X= y. So that the value of x%y is not in a, find [n/2] for the qualified x, y.
Problem solving, from small to large. Let y=a[1]. i1 start from n, let x=a[i1], and output n/2.
Explanation: there is no smaller element than a[1] after sorting.
code;
#include<iostream> #include<algorithm> #include<map> using namespace std; int a[200010]; map<int,int> it; int main() { int t,n,i1,i2,i3,i4,i5; cin >> t; while(t--) { cin >> n; it.clear(); for(i1=1;i1<=n;i1++) cin >> a[i1]; sort(a+1,a+1+n); int num=1; for(i1=n;i1>=n/2,num<=n/2;num++,i1--) cout <<a[i1]<<" " <<a[1]<< endl; } return 0; }
3, C. Poisoned Dagger-Educational Codeforces Round 118 (Rated for Div. 2)
There is a giant dragon whose HP is h. You have a dagger. The dagger itself does no damage to the dragon, but the dagger is highly toxic and can deduct HP from the dragon. Toxicity has a certain duration. The Dagger's toxicity cannot be superimposed, but can be refreshed. That is, if the toxicity can last for 4 seconds, it can be used in the first second and used again in the third second, and can last until the sixth second. Problem, if there are n opportunities to attack the dragon, calculate the minimum toxicity duration k, so that the dragon's h can be zero.
Problem solution 1: use the dichotomy method to take the duration of highly toxic as a variable. If it is less than the time interval, add time directly, otherwise add the duration of highly toxic.
Problem solution 2: in fact, it doesn't need two points. Greed is OK, but it's hard to think. I didn't understand the code written by my classmates. Interested students can check it online. Take the time interval of each attack as an array element, then sort, and finally add an element to be the total health of the dragon. Each time is the remaining blood volume except the remaining rounds. It is assumed that the current time interval is the shortest toxicity duration.
Explanation: normal dichotomy and very difficult greed. But they are all more regular.
code:
/** *@author wrcccccccc */ #include<iostream> using namespace std; #define ll long long ll a[105]; int main() { int t; cin >> t; ll n,m,i1,i2,i3,i4,i5; while(t--) { cin >> n>>m; for(i1=1;i1<=n;i1++) cin >> a[i1]; ll l=1,r=m,mid,ans; while(l<=r) { mid=(l+r)/2; ll p=0; for(i1=1;i1<n;i1++) { if(a[i1+1]-a[i1]<mid) p+=a[i1+1]-a[i1]; else p+=mid; } p+=mid; if(p>=m) {r=mid-1;ans=mid;} else l=mid+1; } cout << ans<< endl; } return 0; }