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连试试水的深浅..... ...
随机推荐
- 关于erlang中的timer:tc/3
timer:tc/3对于统计函数运行时间是个很不错的函数, 截图timer:tc/1,tc/2,tc/3的API: 拿斐波那契数列入手做个讲解: -module(fib). -export([fib/ ...
- 用Cocoapods集成XMPPFramework 遇 Module 'KissXML' not found 问题
用Coacopods集成XMPPFramework完成后Command + B,报Module 'KissXML' not found 一般来说,通过Coacopods集成集成第三方框架,不会再有依赖 ...
- mysql的事务隔离级别及其使用场景
1 什么是事务隔离级别 事务隔离指的是事务之间同步关系. 2 食物隔离级别的分类 第一隔离级别,脏读级别 在脏读级别下,第一个事务修改了某个数据,但是还没有提交,第二个事务可以读取到这个未提及的数据. ...
- yuicompressor
yui/yuicompressor: YUI Compressor https://github.com/yui/yuicompressor YUI Compressor 详细介绍 YUI ...
- Machine Learning in Action(6) AdaBoost算法
Adaboost也是一种原理简单,但很实用的有监督机器学习算法,它是daptive boosting的简称.说到boosting算法,就不得提一提bagging算法,他们两个都是把一些弱分类器组合起来 ...
- js的单线程与异步
一. js 是单线程和异步 1. js 是单线程的,js 的宿主环境(浏览器)是多线程的,实现异步. 2.js是单线程语言,浏览器值分配给js一个主线程,用来执行任务(函数),但一次只能执行一个任务, ...
- 2017广东工业大学程序设计竞赛 E倒水(Water)
题目链接:http://www.gdutcode.sinaapp.com/problem.php?cid=1057&pid=4 题解: 方法一:对n取2的对数: 取对数的公式:s = log( ...
- Django_model基础
Django-model基础 ORM 映射关系: 表名 <-------> 类名 字段 <-------> 属性 表记录 <------->类实例对象 创建表( ...
- html5--3.14 lable元素和label属性
html5--3.14 lable元素和label属性 学习要点 掌握label元素的使用 掌握label属性的使用 lable元素 用来为 input 元素定义标注(标记),建立一个与之相关联的标签 ...
- [Tyvj Aug11] 黄金矿工
传送门 Description 黄金矿工是一个经典的小游戏,它可以锻炼人的反应能力.该游戏中,可以通过“挖矿”获得积分并不断升级.玩家可以在线玩flash版黄金矿工,也可以下载后玩单机版黄金矿工.目前 ...