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)的更多相关文章

  1. Codeforces Round #269 (Div. 2) A B C

    先说C 题目链接:http://codeforces.com/problemset/problem/471/C 题目意思:有 n 张卡,问能做成多少种不同楼层(floor)的 house.注意这 n ...

  2. Codeforces Round #269 (Div. 2) A,B,C,D

    CodeForces - 471A 首先要有四个数相等,然后剩下两个数不同就是Bear,否则就是Elephant. #include <bits/stdc++.h> using names ...

  3. 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 & % ...

  4. Codeforces Round #269 (Div. 2)-D. MUH and Cube Walls,KMP裸模板拿走!

    D. MUH and Cube Walls 说实话,这题看懂题意后秒出思路,和顺波说了一下是KMP,后来过了一会确定了思路他开始写我中途接了个电话,回来kaungbin模板一板子上去直接A了. 题意: ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. Winform 文件控件 - 转

    1. OpenFileDialog private void openFileDialogBTN_Click(object sender, System.EventArgs e) { OpenFile ...

  2. [问题]C# 结构体对齐:如何将变长byte数组对齐

    [StructLayout(LayoutKind.Sequential,Pack=1)] struct Report_Read_Parameter { byte Confirmation; byte ...

  3. 20160722noip模拟赛alexandrali

    [题目大意] 有许多木块, 叠放时, 必须正着叠放, 如图1, 左边两块为合法叠放, 右边为不合法叠放. 图1 一个方块被称为稳定的, 当且仅当其放在最底层, 或其正下方有方块且下方的这个方块的四周都 ...

  4. 项目中的Libevent(多线程)

    多线程版Libevent //保存线程的结构体 struct LibeventThread { LibEvtServer* that; //用作传参 std::shared_ptr<std::t ...

  5. spoj 78

    数学  组合 隔板法 #include <iostream> #include <cstring> #include <cstdio> #include <s ...

  6. LightOj 1096 - nth Term (矩阵快速幂,简单)

    题目 这道题是很简单的矩阵快速幂,可惜,在队内比赛时我不知什么时候抽风把模版中二分时判断的 ==1改成了==0 ,明明觉得自己想得没错,却一直过不了案例,唉,苦逼的比赛状态真让人抓狂!!! #incl ...

  7. sql中临时表的创建和使用【本文转自多人博客】

    本模块原网址:http://www.cnblogs.com/jeffwongishandsome/archive/2009/08/05/1526466.html 原作者:Jeff Wong 1.创建方 ...

  8. iframe标签用法详解(属性、透明、自适应高度)(总结)

    <iframe src="http://www.jb51.net" width="200" height="500"> 脚本之家 ...

  9. POJ2632Crashing Robots

    做模拟题做的我直接睡着了,题并不难,就是一个细心的问题,有一些细节问题注意了就差不多了,代码写的精美的一般找错误也好找一些,应该学着些好看的代码 #include<cstdio> #inc ...

  10. Win7 下硬盘安装Linux Mint 17

    下载Linux Mint 17镜像,放到C盘根目录:解压出mint.iso文件中casper目录下的vmliunz和initrd.lz两个文件,同样放在C盘的根目录里. 在Win7上安装EasyBCD ...