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连试试水的深浅..... ...
随机推荐
- IOS-RSA加解密分享
本文转载至 http://www.cocoachina.com/bbs/read.php?tid=235527 搜索了很多资料,没找到合适的RSA方法,很多人在问这问题,解决了的同志也不分享, ...
- php 批量删除数据
php 批量删除数据 :比如我们在看邮箱文件的时候,积攒了一段时间以后,看到有些文件没有用了 这时候我们就会想到把这些 没用的文件删除,这时候就用到了批量删除数据的功能,这里我是用了数据库原有的一个表 ...
- linux 中添加自己的库路径的方法 cannot open shared object file: No such file or directory
本文转自:http://blog.csdn.net/maotianwang/article/details/44619197 库文档在连接(静态库和共享库)和运行(仅限于使用共享库的程式)时被使用,其 ...
- java会不会出现内存泄露
1 什么是java内存泄露 当java中的对象生命周期已经结束,本应该释放,但是却长时间不能被释放时,也就是说,内存被浪费了,就是内存泄露. 2 java内存泄露的根本原因 长生命周期的对象中持有短生 ...
- please add a 'mainClass’ property
when build an spring project with this command: mvn spring-boot:run there will may show an error mes ...
- 2018年东北农业大学春季校赛 B wyh的矩阵【规律】
题目链接 https://www.nowcoder.com/acm/contest/93/B 思路 先加入 中间的那行 和中间的那列 再减去 最中间那个数 因为它 加了两次 然后逐行往下加 会发现是一 ...
- [NOIP2011提高组day2]-3-观光公交
3.观光公交 (bus.cpp/c/pas) [问题描述] 风景迷人的小城 Y 市,拥有 n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光 ...
- 向HTML页面传入参数
这次是想将参数传入HTML页面,通过js获取参数信息,动态生成HTML页面内容: 方法一: <script> function GetArgsFromHref(sHref, sArgNam ...
- Spring注解原理的详细剖析与实现
本文主要分为三部分: 一. 注解的基本概念和原理及其简单实用 二. Spring中如何使用注解 三. 编码剖析spring@Resource的实现原理 一.注解的基本概念和原理及其简单实用 注解(An ...
- Transaction事务注解和DynamicDataSource动态数据源切换问题解决
问题描述: 写主库开事务的情况下会导致时不时的将更新/插入操作写入到从库上, 导致mysqlException update command denied 问题原因: jetty的工作队列会重用处 ...