首页 > 代码库 > Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
D题fst了,生无可恋。第二场rated的CF,打得精神恍惚
A. Unimodal Array
题意:判断数列是否是单峰的。
像题意那样分为三个阶段随便判一判就好了
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;int n,x[105],part=1;bool f=1;int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&x[i]); if(part==1) {if(x[i]==x[i-1])part=2;else if(x[i]<x[i-1])part=3;} else if(part==2) {if(x[i]<x[i-1])part=3;else if(x[i]>x[i-1]){f=0;break;}} else if(part==3) {if(x[i]>x[i-1]){f=0;break;}else if(x[i]==x[i-1]){f=0;break;}} } if(f)printf("YES\n"); else printf("NO\n"); return 0;}
B. Keyboard Layouts
题意:给出一个26个字母的对应方式, 将给定串由模式1转为模式2
模拟,判断一下大小写
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;char a[26],b[26],s[1001];int map[26];int main(){ scanf("%s%s%s",a,b,s); for(int i=0;i<26;i++) map[a[i]-‘a‘]=b[i]-‘a‘; for(int i=0;i<strlen(s);i++) { if(s[i]>=‘a‘&&s[i]<=‘z‘)cout<<(char)(map[(int)(s[i]-‘a‘)]+‘a‘); else if(s[i]>=‘A‘&&s[i]<=‘Z‘)cout<<(char)(map[(int)(s[i]-‘A‘)]+‘A‘); else cout<<s[i]; } return 0;}
C. Jury Marks
D. Office Keys
题意:给出n个人,k把钥匙,和办公室所在位置,每个人都需拿到一把钥匙再去办公室,最小化他们之中的最大路程
没错…这题我fst了,二分边界开小了,并且某处忘记了j++,心痛
二分答案,然后贪心思路:直觉上可以知道人与钥匙一一对应是从左到右的,根据这点判断是否可行
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>typedef long long LL; int n,k,p,a[1005],b[2005];using namespace std;LL dis(LL x,LL y){return abs(y-x)+abs(p-y);}bool check(LL mid){ int j=1; for(int i=1;i<=n;i++,j++) { while(j<=k&&dis(a[i],b[j])>mid)++j; if(j>k)return false; } return true;}int main(){ scanf("%d%d%d",&n,&k,&p); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=k;i++)scanf("%d",&b[i]); sort(a+1,a+1+n),sort(b+1,b+1+k); LL l=0,r=2000000000,ans; while(l<=r) { LL mid=(l+r)>>1; if(check(mid))ans=mid,r=mid-1; else l=mid+1; } printf("%I64d\n",ans); return 0;}
E. Cards Sorting
F. Bamboo Partition
Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。