Codeforces Round #269 (Div. 2)
A
题意:给出6根木棍,如果有4根相同,2根不同,则构成“bear”,如果剩余两个相同,则构成“elephant”
用一个数组分别储存各个数字出现的次数,再判断即可
注意hash[i]==5的时候,也算作bear,因为它也是满足了4根相同,2根不同
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
int hash[],a[]; int main(){
int i,j,ans=;
memset(hash,,sizeof(hash));
for(i=;i<;i++){
cin>>a[i];
hash[a[i]]++;
} int x=,y=;
for(i=;i<=;i++){
if(hash[i]){
if(hash[i]==||hash[i]==||hash[i]==) x=;
if(hash[i]==||hash[i]==) y=;
}
} if(x&&y) printf("Elephant\n");
else if(x==&&y!=) printf("Bear\n");
else printf("Alien\n");
}
B
题意:给出n个数,按照从小到大的难度级别排序,问是否存在3种及三种以上这样的排序序列
这一题自己没想出来,想得还很复杂= =觉得好乱= = 不过后来看了题解,
发现这样就可以了,再用另一个b数组记录下来相同的数的位置,如果b数组的大小小于等于1,一定不满足
反之,只要b数组里面有两个数,我们就可以通过交换这两个位置(本身排出来有一个序列,分别交换两个位置可以得到两个),得到3个排序序列
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
const int maxn=+;
int b[maxn]; struct node{
int h;
int pos;
} a[maxn]; int cmp(node n1,node n2){
if(n1.h!=n2.h) return n1.h<n2.h;
return n1.pos<n2.pos;
} int main(){
int n,i,j,cnt;
cin>>n;
for(i=;i<=n;i++){
cin>>a[i].h;
a[i].pos=i;
} sort(a+,a+n+,cmp);
cnt=; for(i=;i<=n;i++){
if(a[i].h==a[i-].h){
b[cnt++]=i-;
}
}
if(cnt<=) printf("NO\n");
else{
printf("YES\n");
for(i=;i<n;i++)
printf("%d ",a[i].pos);
printf("%d\n",a[i].pos); swap(a[b[]],a[b[]+]); for(i=;i<n;i++)
printf("%d ",a[i].pos);
printf("%d\n",a[i].pos); // swap(a[b[0]],a[b[0]+1]);//这个地方叫交不交换都可以,交换了即为将第一个位置的换回来,都是不一样的序列
swap(a[b[]],a[b[]+]); for(i=;i<n;i++)
printf("%d ",a[i].pos);
printf("%d\n",a[i].pos);
}
return ;
}
C
题意:给出n个木棍,问能够搭成多少个不同高度的房子
首先想到的是算怎样消耗最少并且能够搭起最高的房子,
观察图可得:横杠之间有n个空隙,就会对应n+1个类似“八”的2根木棒,

这里的第几层是从最高层往最低层数 所以
第0层,0根横杠:1
第1层,1根横杠::1+(1+1)*2 -
第2层,2根横杠:2+(2+1)*2
第i层,i根横杠:i+(i+1)*2=3*i+2
即为满足这样的等差数列就可以消耗最小的房子
然后求前i项和:i*2+(i*(i-1))/2=i*(3*i+1)/2
然后就是自己的doubi思路:想的是,建成最高的了,然后就一层一层得往下拆,看可以拆成多少个高度不同的房子= =一直写不出来
正确的应该是这样:从i=1开始枚举,枚举到i*(3*i+1)/2<=n,这样即为完成消耗最小的房子,
又因为不能有木棒剩余,所以只能3根3根地加, 所以只需要满足n-(i*(3*i)+1)/2能够整除3即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
LL n;
LL ans,tmp,row,sum=; int main(){
cin>>n;
for(LL i=;(tmp=(*i+)*i/)<=n;i++){ if((n-tmp)%==)
ans++;
}
cout<<ans<<"\n";
return ;
}
Codeforces Round #269 (Div. 2)的更多相关文章
- 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) A,B,C,D
CodeForces - 471A 首先要有四个数相等,然后剩下两个数不同就是Bear,否则就是Elephant. #include <bits/stdc++.h> using names ...
- 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)-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连试试水的深浅..... ...
随机推荐
- android 设置半透明
对于Button和ImageButton 还有一些View 设置半透明或者透明都是通过 android:background="#b0000000" 这是就是半透明 android ...
- Flash设置全屏后,放到网页中显示不正常
stage.displayState = StageDisplayState.FULL_SCREEN;//全屏,注意当设置全屏后,放到网页中显示不正常
- AsyncTask不能同时运行多个实例解决办法
在项目中使用AsyncTask时,发现创建的多个实例无法同时运行,比如: AsyncTask t1 = new MyTask(); AsyncTask t2 = new MyTask(); t1.ex ...
- w3c_html_study_note_5.26
xhtml+css 正确的说法 “DIV+CSS”叫法将网页制作者引入两大误区 [误区一]网页中用了Table,页面就不标准,甚至觉着用Table丢人,Table成为了判定页面是否标准的关键点. [误 ...
- Codeforces Round #349 (Div. 1) A. Reberland Linguistics dp
题目链接: 题目 A. Reberland Linguistics time limit per test:1 second memory limit per test:256 megabytes 问 ...
- 【BZOJ】【1085】【SCOI2005】骑士精神
IDA*算法 Orz HZWER A*+迭代加深搜索=IDA* 这题的估价相当于一个可行性剪枝,即如果当前走的步数s+未归位的点数>搜索深度k,则剪枝 /******************** ...
- Android工具包
Eclipse + ADT +SDK,下载ADT Bundle全包含 adt-bundle-windows-x86_64-20140702 http://www.cnblogs.com/tc310/p ...
- js函数:setInterval()/clearInterval()——js网页计时器
一.setInterval()/clearInterval()技术学习 都是window对象的方法,可以直接使用. setInterval(function(){},1000);:每1000毫秒执行一 ...
- 增强学习(Reinforcement Learning and Control)
增强学习(Reinforcement Learning and Control) [pdf版本]增强学习.pdf 在之前的讨论中,我们总是给定一个样本x,然后给或者不给label y.之后对样本进行 ...
- Longest Repeated Sequence【微软编程一小时-题目2】
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a sequence of integers, A = a1, a2, ... an. A c ...