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. android 使某个控件获取焦点

    比如让某个edittext获取焦点,可以调用edittext.requestfocuse()的方法

  2. ACCESS数据库C#操作类(包含事务)

    转自http://blog.csdn.net/allen3010/article/details/6336717 这个是针对ACCESS数据库操作的类,同样也是从SQLHELPER提取而来,分页程序的 ...

  3. 学习Linux第一天

    1.简介: 记住这个名字:Linus Torvals 系统组成:Linux内核,Shell, 文件系统,实时程序 Tips:在系统启动过程中,使用Alt+F2组合键,可以查看Ubuntu启动的详细过程 ...

  4. switch..case函数的基础使用一

    基本作用:switch中的参数与case的值进行比对,相等则进入case. JDK1.7 switch支持int.Integer.String类型 package com.my.test; impor ...

  5. jsp自定义标签分析

    jsp自定义标签的优势体现在于jsp页面上面减少了java代码. jsp自定义标签有三大部分组成,首先是类继承TagSupport,实现doStartTag方法. public int doStart ...

  6. WCF入门(七)——异常处理1

    首先以一个简单的例子演示一下远程调用发生异常的结果: 服务器端代码如下: [ServiceContract] public interface IService1 { [OperationContra ...

  7. SPOJ CNTPRIME 13015 Counting Primes (水题,区间更新,求区间的素数个数)

    题目连接:http://www.spoj.com/problems/CNTPRIME/ #include <iostream> #include <stdio.h> #incl ...

  8. POJ 1852

    #include <iostream> using namespace std; int main() { //freopen("acm.acm","r&qu ...

  9. java基础知识回顾之---java String final类构造方法

    /** * String 构造方法学习 *     String(byte[ ] bytes):通过byte数组构造字符串对象. *     String(byte[] bytes, int offs ...

  10. 防止注入网上查了下用SqlParameter可以,那SqlParameter处理单引号时候是自动转义了吗

    String sql = String.Format(); SqlCommand com = new SqlCommand(sql, con); 一般而言,把 一个单引号,替换成 两个单引号就可以了.