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编程常见问题-程序在模拟器中不显示
新手编程常见问题: 问题表现:程序运行成功,但是在模拟器中不显示 解决办法:检查项目版本和模拟器版本是否匹配或兼容,如果不匹配,选择和模拟器版本一致 项目版本:右键-Properties-androi ...
- 编写一个函数,接受三个string参数,s,oldVal和newVal。使用迭代器及insert和erase函数将s中所有oldVal替换为newVal。测试你的程序,用他替换通用的简写形式,如,将“tho”,将“”“”
// test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- Vim 配置 winmanager
问题描述: winmanager是vim中插件,可以方便的查看当前文件夹中文件,可以切换vim打开文件,非常方便 现在说明安装和使用winmanager 问题解决: (1)winmanager源文件 ...
- dragsort拖动插件的使用
<!DOCTYPE html><html><head> <title>DragSort Example</title> <meta c ...
- Matlab中transpose函数的使用
就是转置的意思,和'一个意思,但是并不重复,因为在cellfun中你无法'这样吧,所以有了这个函数,’只是符号. K>> aa = magic(4) aa = 16 2 3 13 5 11 ...
- PAT-乙级-1054. 求平均值 (20)
1054. 求平均值 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题的基本要求非常简单:给定N个实 ...
- win8双屏敲代码
23寸,AOC冠杰("AOC I2369V 23英寸LED背光超窄边框IPS广视角液晶显示器(银色)") 某东,920买入.
- PHP中如何给日期加上一个月 加一周 加一天
echo date("Y-m-d",strtotime("+1 month",strtotime("2012-02-04"))); 结果 ...
- JS 变量或参数是否有值的判断
var node; …… 判断 node 是否有值,是否为 undefine,是否 null,直接使用两个!!,否定之否定: if (!!node){ .... }else{ .... } 这个条件判 ...
- iframe标签用法详解(属性、透明、自适应高度)(总结)
<iframe src="http://www.jb51.net" width="200" height="500"> 脚本之家 ...