CSU-ACM2016暑假集训比赛2
来源:互联网 发布:groovy 数组 编辑:程序博客网 时间:2024/05/23 02:00
A - 究竟能吃多久?
Time Limit:2000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet knows the schedule: when each of the dishes will be served.
For i-th of the dishes he knows two integer moments in time ai and bi (in seconds from the beginning of the banquet) — when the cooks will bring the i-th dish into the hall and when they will carry it out (ai < bi). For example, if ai = 10 and bi = 11, then the i-th dish is available for eating during one second.
The dishes come in very large quantities, so it is guaranteed that as long as the dish is available for eating (i. e. while it is in the hall) it cannot run out.
The gourmet wants to try each of the n dishes and not to offend any of the cooks. Because of that the gourmet wants to eat each of the dishes for the same amount of time. During eating the gourmet can instantly switch between the dishes. Switching between dishes is allowed for him only at integer moments in time. The gourmet can eat no more than one dish simultaneously. It is allowed to return to a dish after eating any other dishes.
The gourmet wants to eat as long as possible on the banquet without violating any conditions described above. Can you help him and find out the maximum total time he can eat the dishes on the banquet?
Input
The first line of input contains an integer n(1 ≤ n ≤ 100) — the number of dishes on the banquet.
The following n lines contain information about availability of the dishes. The i-th line contains two integers ai and bi(0 ≤ ai < bi ≤ 10000) — the moments in time when the i-th dish becomes available for eating and when the i-th dish is taken away from the hall.
Output
Output should contain the only integer — the maximum total time the gourmet can eat the dishes on the banquet.
The gourmet can instantly switch between the dishes but only at integer moments in time. It is allowed to return to a dish after eating any other dishes. Also in every moment in time he can eat no more than one dish.
Sample Input
Input
3
2 4
1 5
6 9
Output
6
Input
3
1 2
1 2
1 2
Output
0
Hint
In the first example the gourmet eats the second dish for one second (from the moment in time 1 to the moment in time 2), then he eats the first dish for two seconds (from 2 to 4), then he returns to the second dish for one second (from 4 to 5). After that he eats the third dish for two seconds (from 6 to 8).
In the second example the gourmet cannot eat each dish for at least one second because there are three dishes but they are available for only one second (from 1 to 2).
排序 贪心
#include<iostream>#include<stdio.h>#include<cstring>#include<vector>#include<math.h>#include<sstream>#include<algorithm>using namespace std;const int MAX=100+5;const int dR[4]= {-1,0,0,1};const int dC[4]= {0,1,-1,0};int n,totalT,T,mint;int x[10005]= {0};struct dish{ int a; int b; int time;};dish dishes[MAX];bool cmp(dish x,dish y){ if (x.b==y.b) return x.a>y.a; else return x.b<y.b;}int main(){ while (cin>>n) { mint=99999999; totalT=0; for (int i=0; i<n; i++) { cin>>dishes[i].a>>dishes[i].b; dishes[i].time=dishes[i].b-dishes[i].a; mint=min(mint,dishes[i].time); } sort(dishes,dishes+n,cmp); for (T=mint; T>0; T--) { memset(x,0,sizeof(x)); bool flag=true; for (int i=0; i<n; i++) { int cnt=0; for (int j=dishes[i].a; j<dishes[i].b; j++) { if (x[j]==0) { x[j]++; cnt++; if (cnt==T) break; } } if (cnt<T) { flag=false; break; } } if (flag) totalT=max(totalT,n*T); } cout<<totalT<<endl; } return 0;}
B - 为什么我没有糖果?
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Submit
Status
Description
N children standing in circle who are numbered 1 through N clockwise are waiting their candies. Their teacher distributes the candies by in the following way:
First the teacher gives child No.1 and No.2 a candy each. Then he walks clockwise along the circle, skipping one child (child No.3) and giving the next one (child No.4) a candy. And then he goes on his walk, skipping two children (child No.5 and No.6) and giving the next one (child No.7) a candy. And so on.
Now you have to tell the teacher whether all the children will get at least one candy?
Input
The input consists of several data sets, each containing a positive integer N (2 ≤ N ≤ 1,000,000,000).
Output
For each data set the output should be either “YES” or “NO”.
Sample Input
2
3
4
Sample Output
YES
NO
YES
找规律的题目
测试规律的代码:
#include<iostream>#include<stdio.h>#include<cstring>#include<vector>#include<math.h>#include<sstream>#include<set>#include<map>#include<algorithm>using namespace std;typedef long long ll;const ll MAX=1000000005;const int dR[4]= {-1,0,0,1};const int dC[4]= {0,1,-1,0};map<ll,ll> hasCandy;bool p[MAX];int main(){ ll N; while (cin>>N) { memset(p,0,sizeof(p)); hasCandy.clear(); bool flag =true; ll cur=1; p[1]=true; ll cnt=0; int Count=1; while (Count<N) { cur=cur+cnt+1; if (cur>N) cur=cur%N; hasCandy[cnt]=cur; if (!p[cur]) { p[cur]=true; Count++; } if (cnt>=N) { if (hasCandy[cnt]==hasCandy[cnt%N]) { flag=false; break; } } cnt++; } if (flag) cout<<"YES"<<endl; ` else cout<<"NO"<<endl; } return 0;}
提交的代码
#include<iostream>#include<stdio.h>#include<cstring>#include<vector>#include<math.h>#include<sstream>#include<set>#include<map>#include<algorithm>using namespace std;typedef long long ll;const ll MAX=1000000005;const int dR[4]= {-1,0,0,1};const int dC[4]= {0,1,-1,0};vector<ll> vec;int main(){ vec.push_back(1); for (ll i=vec[vec.size()-1]; i<MAX; i=2*i) { vec.push_back(i); } ll N; while (cin>>N) { if (binary_search(vec.begin(),vec.end(),N)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
C - 谁有N个因数?
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output the smallest positive integer with exactly n divisors.
Sample Input
Input
4
Output
6
Input
6
Output
12
没做出来 不是很懂数学方面的东西。
网上的题解用到了唯一分解定理和一些分析。
#include<iostream>#include<stdio.h>#include<cstring>#include<vector>#include<math.h>#include<sstream>#include<set>#include<map>#include<algorithm>using namespace std;typedef long long LL;const LL MAX=1e18+5;bool is_prime[10005];void Eratosthenes(){ memset(is_prime,true,sizeof(is_prime)); is_prime[1]=false; for (int i=2; i<=sqrt(MAX+0.5); i++) if (is_prime[i]) for (int j=i*i; j<=MAX; j+=i) is_prime[j]=false;}int prim[10]= {2,3,5,7,11,13,17,19,23,29};int n;LL ans;void DFS(int a, int b, LL temp){ if(temp<ans && a == n) ans=temp; if(a >= n) return; for(int i=1 ; i<=64 ; i++) { if(ans/prim[b]<temp) break; temp *= prim[b]; DFS(a*(i+1), (b+1), temp); }}int main(){ while(scanf("%d", &n)!=EOF) { ans=MAX; DFS(1, 0, 1); prin`f("%lld\n", ans); } return 0;}
D题模拟 E题看不懂 不是很懂麻将..
F - 比大小?
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large so don’t use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don’t use the function input() in Python2 instead of it use the function raw_input().
Input
The first line contains a non-negative integer a.
The second line contains a non-negative integer b.
The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits.
Output
Print the symbol “<” if a < b and the symbol “>” if a > b. If the numbers are equal print the symbol “=”.
Sample Input
Input
9
10
Output
<
Input
11
10
Output
>
Input
00012345
12345
Output
Input
0123
9
Output
>
Input
0123
111
Output
>
水题
#include<iostream>#include<stdio.h>#include<cstring>#include<vector>#include<math.h>#include<sstream>#include<algorithm>using namespace std;const int MAX=1000000+5;const int dR[4]= {-1,0,0,1};const int dC[4]= {0,1,-1,0};char a[MAX];char b[MAX];int lena,starta;int lenb,startb;int main(){ while(scanf("%s",a)!=EOF) { starta=0; startb=0; scanf("%s",b); lena=strlen(a); lenb=strlen(b); for (int i=0; i<lena; i++) { if (a[i]=='0') starta++; else break; } for (int i=0; i<lenb; i++) { if (b[i]=='0') startb++; else break; } if ((lena-starta)>(lenb-startb)) printf(">\n"); else if ((lena-starta)<(lenb-startb)) printf("<\n"); else { int flag=0; for (; starta<lena&&startb<lenb; starta++,startb++) { if (a[starta]>b[startb]) { flag=1; break; } else if(a[starta]<b[startb]) { flag=-1; break; } } if (flag==0) printf("=\n"); else if (flag==1) printf(">\n"); else if (flag==-1) printf("<\n"); } } return 0;}
- CSU-ACM2016暑假集训比赛2
- CSU-ACM2016暑假集训比赛1
- CSU-ACM2016暑假集训比赛3
- CSU-ACM2016暑假集训比赛4
- CSU-ACM2016暑假集训比赛5
- CSU-ACM2016暑假集训比赛6
- CSU-ACM2016暑假集训比赛7
- CSU-ACM2016暑假集训比赛8
- CSU-ACM2016暑假集训比赛10
- CSU-ACM2016暑假集训比赛11
- CSU-ACM2016暑假集训训练2-DFS
- CSU-ACM2017暑假集训比赛2 C
- CSU-ACM2017暑假集训比赛2 D
- CSU-ACM2017暑假集训比赛2 B
- CSU-ACM2017暑假集训比赛2 A
- CSU-ACM2017暑假集训比赛2 E
- CSU-ACM2017暑假集训比赛2 HDU
- CSU-ACM2017暑假集训比赛2 CodeForces
- GCD使用经验与技巧浅谈
- Java Web学习(18):JavaBean四大作用域
- POJ 1062 昂贵的聘礼
- github下fork后如何同步源库的新更新内容?
- linux基础——linux进程间通信(IPC)机制总结
- CSU-ACM2016暑假集训比赛2
- poj1026Cipher
- HDU 1892 See you~
- 8086汇编语言 除数8位DIV指令实例
- Android集成微信支付让你不再踩坑
- 批量修改文件(或文件夹)权限或所有者
- c++设计模式之装饰模式
- 停止线程
- HDU 1445 Ride to School 贪心