Codeforces Round #350 (Div. 2)
来源:互联网 发布:手机一键截屏软件下载 编辑:程序博客网 时间:2024/06/06 23:56
链接:http://codeforces.com/contest/670
problemA Holidays:先假设没有闰年,然后给出一个n,求连续的n天中,周末最少能有多少天,最多能有多少天。
分析:对7去余,然后判一下就行了。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=100010;const int MAX=1000000100;const int mod=100000000;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=998244353;const int INF=1000000010;typedef double db;typedef unsigned long long ull;int main(){ int k,g,n,mx,mi; scanf("%d", &n); k=n/7;g=n%7; if (g==6) { mx=2*k+2;mi=2*k+1; } else if (g<=2) { mx=2*k+g;mi=2*k; } else { mx=2*k+2;mi=2*k; } printf("%d %d\n", mi, mx); return 0;}
problemB Game of Robots:给定一个n个元素的数组a和一个k,用1到n去构造出一个新的数组,当用i构造时将a数组的a[1]~a[i]加到新数组后面。求新数组的第k个元素是多少。
分析:暴力。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=100010;const int MAX=1000000100;const int mod=100000000;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=998244353;const int INF=1000000010;typedef double db;typedef unsigned long long ull;int a[N];int main(){ int i,n,k; scanf("%d%d", &n, &k); for (i=1;i<=n;i++) scanf("%d", &a[i]); for (i=1;i<=n;i++) if (k>i) k-=i; else break ; printf("%d\n", a[k]); return 0;}
problemC Cinema:给定n个人的审美值a,给定m部电影的观赏度A和观赏度B,选出一部电影使得审美a==A最多,相同时使a==B最多。
分析:map存下来,扫一遍即可。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=200010;const int MAX=1000000100;const int mod=100000000;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=998244353;const int INF=1000000010;typedef double db;typedef unsigned long long ull;map<int,int>M;int b[N],c[N];int main(){ int i,n,m,x,ans=1,mx=0,mxx=0; scanf("%d", &n); for (i=1;i<=n;i++) { scanf("%d", &x);M[x]++; } scanf("%d", &m); for (i=1;i<=m;i++) scanf("%d", &b[i]); for (i=1;i<=m;i++) scanf("%d", &c[i]); for (i=1;i<=m;i++) if ((M[b[i]]>mx)||(M[b[i]]==mx&&M[c[i]]>mxx)) { ans=i;mx=M[b[i]];mxx=M[c[i]]; } printf("%d\n", ans); return 0;}
problemD Magic Powder:给定饼干各个材料的使用量和k克魔法材料,给出已有的各个材料的量,每克魔法材料能变成任意一种材料的一克。求使用这些材料最多能做多少饼干。
分析:二分答案即可。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=100010;const int MAX=2000000010;const int mod=100000000;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=998244353;const int INF=1000000010;typedef double db;typedef unsigned long long ull;int n;ll k,a[N],b[N];int check(int x) { int i; ll kk=k; for (i=1;i<=n;i++) if (a[i]*x>b[i]) { if (kk<a[i]*x-b[i]) return 0; else kk-=a[i]*x-b[i]; } return 1;}int main(){ int i; scanf("%d%I64d", &n, &k); for (i=1;i<=n;i++) scanf("%d", &a[i]); for (i=1;i<=n;i++) scanf("%d", &b[i]); ll l=0,r=MAX,mid=(l+r)>>1; while (l+1<r) if (check(mid)) { l=mid;mid=(l+r)>>1; } else { r=mid;mid=(l+r)>>1; } printf("%I64d\n", l); return 0;}
problemE Correct Bracket Sequence Editor:给定一个长度为n的合法的括号序列和初始光标的位置q,接下来给定m个操作:1:光标向左移。2:光标向右移。3:删除当前光标所在的那一对括号之间所有的括号(闭区间)。输出最后的括号序列。
分析:用双向链表模拟整个过程即可。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=500010;const int MAX=1000000100;const int mod=100000000;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=998244353;const int INF=1000000010;typedef double db;typedef unsigned long long ull;int d[N],p[N],w[N],pre[N],sub[N];char s[N],c[N];int main(){ int i,n,m,q,l,r,k=0; scanf("%d%d%d", &n, &m, &q); scanf("%s", s); scanf("%s", c); for (i=n;i;i--) if (s[i-1]==')') { p[i]=p[i+1]+1;d[++k]=i; } else { p[i]=p[i+1]-1;w[i]=d[k];k--; } for (i=1;i<=n;i++) w[w[i]]=i; for (i=0;i<=n+1;i++) pre[i]=i-1,sub[i]=i+1; for (i=0;i<m;i++) if (c[i]=='L') { if (pre[q]!=0) q=pre[q]; } else if (c[i]=='R') { if (sub[q]!=n+1) q=sub[q]; } else { if (q==0) continue ; l=min(q,w[q]);r=max(q,w[q]); if (sub[r]!=n+1) q=sub[r]; else q=pre[l]; sub[pre[l]]=sub[r];pre[sub[r]]=pre[l]; } k=sub[0]; while (k<=n) { printf("%c", s[k-1]);k=sub[k]; } printf("\n"); return 0;}
problemF Restore a Number:给定两个字符串s,t,只包含'0'~'9'。有一个原数字Q,s包含了Q中的所有数字和Q长度len的所有数字,t是Q的一个子串。题目数据保证有解,求出满足条件的最小的Q。
分析:首先我们能知道,我们能暴力枚举长度len(显然len越小越好),然后简单的判断就能确定是否有解。当我们找到最小长度len时,我们只要将s减去len中的数字和t中的数字,我们就能知道剩下了哪些,然后我们用剩下的这些数字和子串t去构造一个字典序最小的数即可。1:当剩下的元素中没有非0元素时或剩下的元素组成的字符串放在t后面是更优时,我们只要将t作为前缀,然后将剩下的元素接在后面即可。2:当我们不用将t当前缀时,剩下的元素组成的必然是一个没有前缀0然后是aaabbccc这种字符串,然后我们只要找到将t串插入的位置即可。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=1000010;const int MAX=151;const int mod=100000000;const int MOD1=100000007;const int MOD2=100000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=1000000000;const ll INF=10000000010;typedef double db;typedef unsigned long long ull;char s[N],c[N],d[N];int les,lec,x[10],y[10],z[10];int check(int w) { int i,k=0,g=0,W=w; memset(z,0,sizeof(z)); while (w) { g++;z[w%10]++;w/=10; } if (les!=W+g) return 0; for (i=0;i<10;i++) if (x[i]<y[i]+z[i]) return 0; for (i=1;i<10;i++) if (x[i]>y[i]+z[i]) k++; if (!k&&c[0]=='0') return 0; return 1;}int compare(int lec,int led) { char C,D; for (int i=0;i<lec+led;i++) { if (i<lec) C=c[i]; else C=d[i-lec]; if (i<led) D=d[i]; else D=c[i-led]; if (C<D) return 1; if (C>D) return 0; } return 1;}void print_out(int w) { int i,j,k=0,W=w,bo=0; for (i=0;i<10;i++) x[i]-=y[i]; while (w) { x[w%10]--;w/=10; } for (i=1;i<10;i++) for (j=1;j<=x[i];j++) d[k++]=i+'0'; for (i=k-1;i>0;i--) d[i+x[0]]=d[i]; if (k) for (i=1;i<=x[0];i++) d[i]='0'; else for (i=0;i<x[0];i++) d[i]='0'; k+=x[0];d[k]='\0'; if (k==0) { printf("%s\n", c);return ; } if (d[0]=='0'||(c[0]!='0'&&compare(lec,k))) { printf("%s", c); for (i=0;i<10;i++) for (j=1;j<=x[i];j++) printf("%c", i+'0'); printf("\n"); } else { printf("%c", d[0]); for (i=1;i<lec;i++) if (c[i]!=c[i-1]) { if (c[i]>c[i-1]) bo=1;break ; } if (bo) { for (i=1;i<k;i++) if (d[i]>c[0]) break ; else printf("%c", d[i]); printf("%s", c); for (j=i;j<k;j++) printf("%c", d[j]); printf("\n"); } else { for (i=1;i<k;i++) if (d[i]>=c[0]) break ; else printf("%c", d[i]); printf("%s", c); for (j=i;j<k;j++) printf("%c", d[j]); printf("\n"); } }}int main(){ int i; scanf("%s%s", s, c); les=strlen(s);lec=strlen(c); for (i=0;i<les;i++) x[s[i]-'0']++; for (i=0;i<lec;i++) y[c[i]-'0']++; if (les==2&&lec==1&&x[0]==1&&x[1]==1&&y[0]==1) { printf("0\n");return 0; } for (i=1;i<=les;i++) if (check(i)) { print_out(i);break ; } return 0;}
0 0
- codeforces Round#350 Div.2
- Codeforces Round #350(Div 2)
- Codeforces Round #350 (Div. 2)
- Codeforces Round #350 (Div. 2)
- Codeforces Round #350 (Div. 2)
- Codeforces Round #350 (Div. 2)
- Codeforces Round #350 (Div. 2)easy
- Codeforces Round #350 (Div. 2) C Cinema
- Codeforces Round #350 (Div. 2)(B)
- Codeforces Round #350 (Div. 2) (二分答案)
- Codeforces Round #350 (Div. 2) ABCDE
- Codeforces Round #350 (Div. 2) 题解
- Codeforces Round #350 (Div. 2) C. Cinema
- 【解题报告】Codeforces Round #350 (Div. 2)
- Codeforces Round #350 (Div. 2) E 链表
- Codeforces Round #350 (Div. 2) A
- Codeforces Round #350 (Div. 2) B
- Codeforces Round #350 (Div. 2) C
- 【知乎】verilog相关知识杂谈
- c++第五次实验-1
- ZipFile v.s. ZipInputStream in java.util.zip
- 背包九讲
- leetcode(2), Nin Game详解(python)
- Codeforces Round #350 (Div. 2)
- Java核心基础(1) 基本语法
- matlab2014a中help与参考页翻译 Tutorials-matrices and arrays- Array Creation
- CodeForces 483A Counterexample
- 《深度探索C++对象模型》学习笔记之Data语意学
- 当我加载配置文件时报错:Call to undefined method CI_Config::config()
- 四种最短路径算法对比
- [Android]百度地图开发之SDK开发环境搭建
- Android真机无法链接eclipse,解决方案