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连试试水的深浅..... ...
随机推荐
- h5的复制功能
js+html5实现复制文字按钮 <div> <input type="text" name="guanfangaddress" id=&qu ...
- aapt命令获取apk具体信息(包名、版本号号、版本号名称、兼容api级别、启动Activity等)
aapt命令获取apk具体信息(包名.版本号号.版本号名称.兼容api级别.启动Activity等) 第一步:找到aapt 找到sdk的根文件夹,然后找到build-tools文件夹.然后会看到一些b ...
- 有返回值的Bookmark
首先代码创建Activity: public sealed class WaitForResponse<TResult>:NativeActivity<TResult> { p ...
- Android Handle,Looper,Message消息机制
尊重原创,转载请标明出处 http://blog.csdn.net/abcdef314159 我们知道在Android中更新UI都是在主线程中,而操作一些耗时的任务则须要在子线程中.假设存在多个 ...
- windows搭建FTP服务器实战
第一步:创建用户名密码(ftp使用) 1.1.点击“开始”菜单,选择“控制面板”. 1.2.选择“管理工具”—>“计算机管理” 1.3. 选择“本地用户和组”下的用户,右键选择“新用户” 输入用 ...
- AbstractFactory Pattern
AbstractFactory模式用来解决这类问题:要创建一组相关或者相互依赖的对象. AbstractFactory Pattern结构图 实现: #ifndef _PRODUCT_H_ #defi ...
- jquery特效(7)—弹出遮罩层且内容居中
上周写了几个小特效,其中有个点击按钮弹出遮罩层的特效,下面来看最终实现的效果: 由于是测试的程序,所以我未加关闭的按钮. 一.主体程序 <!DOCTYPE html> <html&g ...
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或
题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible so ...
- 小trick之mklink
因为要看很多论文就下载安装了zotero,又因为文献库的文件夹在安装目录太深,找起来太麻烦,再加上是软件本身的安装目录,因此把论文都下载在默认文件中总会天然地产生不安全感,万一误删软件怎么办.所以在文 ...
- 【UVA12779占位】Largest Circle
几何题,希望有时间回来解决掉.