Question A: couple doubi
Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4861
This question is tricky. At the beginning, there was no idea at all. At the beginning, I started to look at the question a little like the ferma theorem, but I only know this theorem and I never used it. After reading the definition, what is a little different is the opposite, and then the opposite will not be converted, Nima, thus missing the best solution. Then the teammates understood the incorrect question. Wa sent multiple times, and then I read the question again. Then my teammates realized that they understood the wrong question and found the rule.
The code is too short to be pasted. Write it.
if(k/(p-1)&1) puts("YES");else puts("NO");
D: Task
Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4864
This question was right at the beginning. Put the machine and task in the same number group, and then sort the tasks from large to small based on the time and level. However, the time knows how to obtain the task, but the time level is unknown. So I don't dare to think about it, and I don't know how to deal with it when the time is big, and which one to choose when the level is big. Then ...... Then I knew how to handle the problem, but it was no longer necessary. After reading Qi Shen, It's really witty to use Multiset to handle it.
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<bitset>#define INF 100007using namespace std;typedef long long ll;typedef unsigned long long ull;struct abc{ int ti,le,ty;}a[200005];bool cmp(abc a,abc b){ if(a.ti!=b.ti) return a.ti>b.ti; if(a.le!=b.le) return a.le>b.le; return a.ty>b.ty;}multiset<int>s;int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { int i,j,cnt=0; ll sum=0,sum1=0; s.clear(); for(i=0;i<n;i++) scanf("%d%d",&a[cnt].ti,&a[cnt].le), a[cnt++].ty=1; for(i=0;i<m;i++) scanf("%d%d",&a[cnt].ti,&a[cnt].le), a[cnt++].ty=0; sort(a,a+cnt,cmp); for(i=0;i<cnt;i++) { if(a[i].ty) s.insert(a[i].le); else { multiset<int>::iterator it=s.lower_bound(a[i].le); if(it!=s.end()) sum1++,sum+=500*a[i].ti+2*a[i].le,s.erase(it); } } printf("%I64d %I64d\n",sum1,sum); } return 0;}