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连试试水的深浅..... ...
随机推荐
- iOS8需要兼容的内容
本文转载至 http://blog.csdn.net/liuwuguigui/article/details/39494435 1.iPad上使用presentModalViewController ...
- php 批量删除数据
php 批量删除数据 :比如我们在看邮箱文件的时候,积攒了一段时间以后,看到有些文件没有用了 这时候我们就会想到把这些 没用的文件删除,这时候就用到了批量删除数据的功能,这里我是用了数据库原有的一个表 ...
- Java类加载器( 死磕9)
[正文]Java类加载器( CLassLoader ) 死磕9: 上下文加载器原理和案例 本小节目录 9.1. 父加载器不能访问子加载器的类 9.2. 一个宠物工厂接口 9.3. 一个宠物工厂管理 ...
- Android笔记之Snackbar的基本使用
使用Snackbar之前,须导入com.android.support:design 使用示例 package com.bu_ish.snackbar_test; import android.gra ...
- 如何克隆UBUNTU14.04LTS
先对目标盘sdb做好处理,分区,格式化,挂载等操作sudo fdisk /dev/sdb1fdisk常用命令如下,m是帮助,n创建新分区,d删除分区,w保存退出.分好区后,对sdb1进行格式化和挂载: ...
- IDEA 打开多个项目
简单的说只需要以下几步: 1.将需要同时打开的模块放在一个文件夹下,e.g. AModel 和 BModel 同时放在 Project 文件夹下. 2.在 IDEA 初始导入项目页面选择 open - ...
- the art of seo(chapter four)
SEO Implementation:First Stages ***Development Platform and Information Architecture***1.Technology ...
- js日期的初始化的格式
js在初始化日期对象时,如果有传入日期.则格式有兼容性问题: //下面的写法在谷歌下没有问题,在火狐和ie下有问题var time = new Date('2014-11-27 00:00:00'); ...
- 001-将Python源码转换为不需要环境的可执行文件
1 安装pyinstaller pip install pyinstaller #或者 pip3 install pyinstaller 2 生成打包文件 在命令行中输入 pyinstaller -F ...
- VirtualBox下安装ubuntu图文教程以及软件安装
一. 下载安装VirtualBox 官网下载VirtualBox,目前版本:VirtualBox 5.1.8 for Windows hosts x86/amd64 下载好了安装VirtualBox, ...