Codeforces Round #269 (Div. 2) A,B,C,D
CodeForces - 471A
首先要有四个数相等,然后剩下两个数不同就是Bear,否则就是Elephant。
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII; int num[10];
int a; int main()
{
memset(num,0,sizeof(num));
for(int i=1;i<=6;i++)
{
scanf("%d",&a);
num[a]++;
}
bool flag=false;
for(int i=1;i<=9;i++){
if(num[i]>=4){
num[i]-=4;
flag=true;
break;
}
}
if(flag){
for(int i=1;i<=9;i++){
if(num[i]==2){
puts("Elephant");
return 0;
}
}
puts("Bear");
}
else{
puts("Alien");
}
return 0;
}
CodeForces - 471B
先要判断满足,然后sort完本身是一种,然后交换一次又是一种,标记掉,再交换,就有三种了。
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
int tp;
int num[2010];
int n;
struct asd{
int id;
int w;
};
asd a[2010];
bool cmp(asd x,asd y){
if(x.w==y.w) return x.id<y.id;
return x.w<y.w;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].w);
num[a[i].w]++;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
int sum=1;
for(int i=1;i<=2000;i++){
if(num[i]){
sum*=num[i];
if(sum>=3){
puts("YES");
for(int i=1;i<=n;i++)
printf("%d ",a[i].id);
puts("");
for(int i=1;i<=n;i++){
if(i+1<=n){
if(a[i].w==a[i+1].w){
printf("%d %d ",a[i+1].id,a[i].id);
tp=i;
i++;
}
else
printf("%d ",a[i].id);
}
else
printf("%d ",a[i].id);
}
puts("");
for(int i=1;i<=n;i++){
if(i+1<=n){
if(a[i].w==a[i+1].w&&i!=tp){
printf("%d %d ",a[i+1].id,a[i].id);
i++;
}
else
printf("%d ",a[i].id);
}
else
printf("%d ",a[i].id);
}
return 0;
}
}
}
puts("NO");
return 0;
}
CodeForces - 471C
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int main()
{
LL n;
int k=0;
scanf("%lld",&n);
for(LL i=3-n%3;; i+=3)
{
if((2*(n+i))<(3*i*(i+1))) break;
k++;
}
printf("%d\n",k);
return 0;
}
CodeForces - 471D
思路:
先特判掉m=1的时候,因为只要满足变化规律匹配就OK,所以相邻做个差,得到两个新串,然后就是求b串在a串里出现的次数(注意这个次数aa在aaa中出现2次),KMP即可;
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=2e5+10;
int n,m;
int a[N],b[N];
int a_num,b_num;
int Next[N]; void GetNext()
{
int i=0,j=-1;
Next[0]=-1;
while(i<b_num){
if(j==-1||b[i]==b[j])
Next[++i]=++j;
else
j=Next[j];
}
} int KMP()
{
GetNext();
int ans=0;
int i=0,j=0;
while(i<a_num){
if(j==-1||a[i]==b[j])
{
i++;
j++;
if(j==b_num){
j=Next[j];
ans++;
}
}
else
j=Next[j];
}
return ans;
} int main()
{
int pre,x;
scanf("%d%d",&n,&m);
if(m==1){
printf("%d\n",n);
return 0;
}
a_num=b_num=0;
scanf("%d",&pre);
for(int i=2;i<=n;i++){
scanf("%d",&x);
a[a_num++]=x-pre;
pre=x;
}
scanf("%d",&pre);
for(int i=2;i<=m;i++){
scanf("%d",&x);
b[b_num++]=x-pre;
pre=x;
}
printf("%d\n",KMP());
return 0;
}
Codeforces Round #269 (Div. 2) A,B,C,D的更多相关文章
- Codeforces Round #269 (Div. 2) A B C
先说C 题目链接:http://codeforces.com/problemset/problem/471/C 题目意思:有 n 张卡,问能做成多少种不同楼层(floor)的 house.注意这 n ...
- Codeforces Round #269 (Div. 2) D - MUH and Cube Walls kmp
D - MUH and Cube Walls Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & % ...
- Codeforces Round #269 (Div. 2)
A 题意:给出6根木棍,如果有4根相同,2根不同,则构成“bear”,如果剩余两个相同,则构成“elephant” 用一个数组分别储存各个数字出现的次数,再判断即可 注意hash[i]==5的时候,也 ...
- Codeforces Round #269 (Div. 2)-D. MUH and Cube Walls,KMP裸模板拿走!
D. MUH and Cube Walls 说实话,这题看懂题意后秒出思路,和顺波说了一下是KMP,后来过了一会确定了思路他开始写我中途接了个电话,回来kaungbin模板一板子上去直接A了. 题意: ...
- Codeforces Round #269 (Div. 2) B. MUH and Important Things
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from t ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- 04 svn设置开机启动
一:设置开机启动[dos命令] 格式: sc create 服务名称 binPath=空格"安装目录/svnserve.exe -r 版本库地址目录 --service" star ...
- 怎样得到QML package的具体API接口
虽然我们的developer站点有丰富的API介绍,可是,有些API的介绍可能并不全,有些API也在不断地演进中. 为了得到更具体的API,我们能够通过例如以下的命令来得到更加具体的信息.比方我们对& ...
- AndroidPageObjectTest_Chained.java
以下代码使用ApiDemos-debug.apk进行测试 //这个脚本用于演示PageFactory的功能:链式注解@AndroidFindBys.@IOSFindBys.具体用法参考页面类的代码. ...
- CentOS 6.9 安装 ftp 服务器
昨天为了方便上传写好的博客 .md 文件到服务器上,就在服务器搭建了一个 ftp 服务端用来上传写好的博客.很久之前我也使用虚拟机搭建过 ftp 服务器,但是时间久了,很多都忘记了.于是乎又一顿 Go ...
- Gradle build-info.xml not found for module app.Please make sure that you are using gradle plugin '2.0.0-alpha4' or higher.
解决方法:去掉“Enable Instant run to host swap code/resource changes on deploy(default enabled)”的勾选项 Settin ...
- 003-更改pip的源让下载安装更加快捷
1 找到pip目录 C:\Python36\Lib\site-packages\pip\models 2 修改下面的index.py文件 将url设定为 https://pypi.douban.com ...
- kali本機安裝openvas的血淚史復盤
安裝openvas的血淚史 因爲學習的需要,需要裝openvas,但是在虛擬機裏面,無論怎麼更新跟新源,總是會有問題,一氣之下,便不用虛擬機了,將自己的物理機刷成了kali機,從此便進了一個大坑. 安 ...
- C++之new和delete
new 和 delete 是 C++ 用于管理 堆内存 的两个运算符,对应于 C 语言中的 malloc 和 free,但是 malloc 和 free 是函数,new 和 delete 是运算符.除 ...
- AtCoder Grand Contest 012 D:Colorful Balls
题目传送门:https://agc012.contest.atcoder.jp/tasks/agc012_d 题目翻译 给你一排一共\(N\)个球,每个球有一个颜色\(c_i\)和一个重量\(w_i\ ...
- AndroidStudio自动弹出Documentation
AndroidStudio自动弹出Documentation窗口 例如,在布局文件中添加 Button 标签 敲完 <Butotn 回车后就自动出现 Documentation窗口 那如何关闭自 ...