Codeforces Round #269 (Div. 2) A B C
来源:互联网 发布:ftp服务器源码 编辑:程序博客网 时间:2024/05/17 02:41
先说C
题目链接:http://codeforces.com/problemset/problem/471/C
题目意思:有 n 张卡,问能做成多少种不同楼层(floor)的 house,注意这 n 张卡都要用光。每层 floor 都由一定的 room 构成,每两个相邻 room 规定要有一个公共的ceiling。规定从上到下看,每层 floor 的 room 的数量呈递增的形式排布。
这种东西一般就是看图,先自己从小数开始推算找规律 可以发现第i层需要(3*i+2)个,那么前i层总的最少需要就是等差数列求和得(3*i+1)*i/2。 因为不能剩余,那么n-(3*i+1)*i/2必须能被3整除,那么从1到(3*i+1)*i/2<=n遍历一下就行 n=10^12 所以O(1e6)时间还是够的
//#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <iostream>#include <iomanip>#include <cmath>#include <map>#include <set>#include <queue>using namespace std;#define ls(rt) rt*2#define rs(rt) rt*2+1#define ll long long#define ull unsigned long long#define rep(i,s,e) for(int i=s;i<e;i++)#define repe(i,s,e) for(int i=s;i<=e;i++)#define CL(a,b) memset(a,b,sizeof(a))#define IN(s) freopen(s,"r",stdin)#define OUT(s) freopen(s,"w",stdout)const ll ll_INF = ((ull)(-1))>>1;const double EPS = 1e-8;const double pi = acos(-1.0);const int INF = 100000000;int main(){ ll n; while(~scanf("%I64d",&n)) { ll ans=0,tmp; for(ll i=1;(tmp=(3*i+1)*i/2)<=n;i++) { if( ( n-tmp )%3 == 0) ans++; } printf("%I64d\n",ans); } return 0;}
B, 首先能不能出现三种以上的排列,写代码时用了类似离散化的写法,能的话 就随便改两个数的次序就能凑够3种
//#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <iostream>#include <iomanip>#include <cmath>#include <map>#include <set>#include <queue>using namespace std;#define ls(rt) rt*2#define rs(rt) rt*2+1#define ll long long#define ull unsigned long long#define rep(i,s,e) for(int i=s;i<e;i++)#define repe(i,s,e) for(int i=s;i<=e;i++)#define CL(a,b) memset(a,b,sizeof(a))#define IN(s) freopen(s,"r",stdin)#define OUT(s) freopen(s,"w",stdout)const ll ll_INF = ((ull)(-1))>>1;const double EPS = 1e-8;const double pi = acos(-1.0);const int INF = 100000000;const int MAXN = 2000+20;struct Node{ int id,v;}p[MAXN];int n;bool cmp(Node a, Node b){ return a.v<b.v;}void print(){ printf("%d",p[1].id); for(int i=2;i<=n;i++) printf(" %d",p[i].id); putchar('\n');}void SW(Node &a, Node &b){ Node tmp; tmp=a; a=b; b=tmp;}int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) { scanf("%d",&p[i].v); p[i].id=i; } sort(p+1,p+n+1,cmp); p[n+1].v=-1; int tmp=1,pre=p[1].v; ll cnt=1; int flag=0; for(int i=2;i<=n+1;i++) if(pre!=p[i].v) { if(tmp>=3){flag=1;break;} cnt*=tmp; if(cnt>=3){flag=1;break;} tmp=1; pre=p[i].v; } else { tmp++; } if(!flag)puts("NO"); else { puts("YES"); print(); int pr=p[1].v,tmp=1; int cnt=1; for(int i=2;i<=n+1;i++)/// if(pr!=p[i].v) { if(tmp==2) { SW(p[i-1],p[i-2]); if(cnt<3)print(),cnt++;; } if(tmp >= 3) { SW(p[i-1],p[i-2]); if(cnt<3) print(),cnt++; //cnt++; SW(p[i-1],p[i-3]); if(cnt<3)print(),cnt++; //cnt++; } if(cnt >=3)break; tmp=1; pr=p[i].v; } else { tmp++; } } } return 0;}
A 水 不过因为flag少写了一个 WA了一次
//#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <iostream>#include <iomanip>#include <cmath>#include <map>#include <set>#include <queue>using namespace std;#define ls(rt) rt*2#define rs(rt) rt*2+1#define ll long long#define ull unsigned long long#define rep(i,s,e) for(int i=s;i<e;i++)#define repe(i,s,e) for(int i=s;i<=e;i++)#define CL(a,b) memset(a,b,sizeof(a))#define IN(s) freopen(s,"r",stdin)#define OUT(s) freopen(s,"w",stdout)const ll ll_INF = ((ull)(-1))>>1;const double EPS = 1e-8;const double pi = acos(-1.0);const int INF = 100000000;int len[10],vis[12];int main(){ while(~scanf("%d%d%d%d%d%d",len,len+1,len+2,len+3,len+4,len+5)) { int ans=0; CL(vis,0); sort(len,len+6); int cnt=0,flag=0; for(int i=0;i<6;i++) { vis[len[i]]++; if(vis[len[i]] == 4)cnt=i,flag=1; } if(vis[len[cnt]] == 5) { puts("Bear"); continue; } if(vis[len[cnt]] == 6) { puts("Elephant"); continue; } int last=-1,ff=0; for(int i=0;i<6;i++) if(i!=cnt) { if(vis[len[i]] == 2)ff=1; if(last==-1){len[0]=len[i];last=1;} else len[5]=len[i]; } if(ff && flag) { puts("Elephant"); continue; } if(len[0]!=len[5] && flag) { puts("Bear"); continue; } if(len[0]==len[5] && flag) { puts("Elephant"); continue; } puts("Alien"); } return 0;}
1 0
- Codeforces Round #269 (Div. 2) A B C
- Codeforces Round #269 (Div. 2) A,B,C,D
- Codeforces Beta Round #95 (Div. 2) A B C E
- 【CodeForce】Codeforces Round #140 (Div. 2) A B C
- 【CodeForce】Codeforces Round #142 (Div. 2) A B C
- Codeforces Round #160 (Div. 2)——A,B,C
- Codeforces Round #177 (Div. 2)——A,B,C
- Codeforces Round #179 (Div. 2)A、B、C、D
- Codeforces Round #184 (Div. 2)——A,B,C
- Codeforces Round #185 (Div. 2)——A,B,C
- Codeforces Round #186 (Div. 2)——A,B,C
- Codeforces Round #186 (Div. 2)A、B、C、D、E
- Codeforces Round #190 (Div. 2) A B C
- Codeforces Round #196 (Div. 2) A,B,C
- Codeforces Round #202 (Div. 2) (A、B、C、D)
- Codeforces Round #211 (Div. 2)(A,B,C,D)
- Codeforces Round #218,#217 (Div. 2) A.B.C
- Codeforces Round #220 (Div. 2)(A,B,C,D)
- Android ViewPager程序引导页的实现
- 如何打造舒适的Linux使用环境
- NAS DIY(2)配件清单
- C语言_数组应用
- CSS控制效果
- Codeforces Round #269 (Div. 2) A B C
- 易宝面试
- javascript继承机制
- 地图标绘系统V1.0测试版(javascript)-GIS520社区
- UVA1400 - "Ray, Pass me the dishes!"
- (原创)优酷android客户端 下载中 bug 解决
- Silver Cow Party - POJ 3268 spfa
- JSON-RPC 2.0规范 翻译 中文版
- pcb各层介绍