Codeforces Round #428 (Div. 2) ABCD
来源:互联网 发布:postgresql mysql迁移 编辑:程序博客网 时间:2024/06/05 21:08
A.傻逼题
你每天只能给那个人最多8个,多的可以下一天再给他。
//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db doubletypedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=1e3+10;const int maxx=1e6+100;const double EPS=1e-8;const double eps=1e-8;const int mod=10000007;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;int a[maxn];int main(){ int n,k,x; cin>>n>>k; int sum=0,val=0; FOR(1,n,i) cin>>a[i]; FOR(1,n,i) { if(a[i]>8) { sum+=8; a[i+1]+=a[i]-8; } else { sum+=a[i]; } if(sum>=k) { cout<<i<<endl; return 0; } } cout<<-1<<endl;}
B .坑题。
题目大意:飞机有n排,每排8个座位,其中12,3456,78分别靠在一起,现在有k个不同的团体,每个团体有a[i]人,问是否存在一种分配座位的方案使得每个团体不和别的团体的人相邻。
hack数据:
2 7
2 2 2 2 2 2 2 yes
先处理中间的,也就是说如果有4个人以上的团体,把中间位置的先占了,这样一定是自己人相邻,另外剩下2个人以上的先把中间剩下的坑算一半进去,也就是本来中间是有2*n个位置 (我把2个相邻的当做一个位置),那么我剩下的2个人的以上的团体,如果要占中间位置,只能占一个坑,另外一个坑必须留出来,也就是 0011这样。 如果是2211就不行。那么剩下的就是奇数个的情况了。那么之前中间本来有0011这样,我奇数个的就可以插进去
2011这样。所以就有了如下代码:
//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db double#define ll long longtypedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=1e3+10;const int maxx=1e6+100;const double EPS=1e-8;const double eps=1e-8;const int mod=1e9+7;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;int a[maxx];int main(){ int n,k; cin>>n>>k; FOR(1,k,i) cin>>a[i]; int sum1=n,sum2=2*n; FOR(1,k,i) { int t=min(a[i]/4,sum1); sum1-=t; a[i]-=4*t; } sum2+=sum1; FOR(1,k,i) { int t=min(a[i]/2,sum2); sum2-=t; a[i]-=2*t; } sum2+=sum1; FOR(1,k,i) { sum2-=a[i]; } if(sum2>=0) puts("YES"); else puts("NO");}C.这里
D.这里
阅读全文
0 0
- Codeforces Round #428 (Div. 2) ABCD
- Codeforces Beta Round #67 (Div. 2) ABCD
- Codeforces Round #191 (Div. 2) ABCD
- Codeforces Round #193 (Div. 2) ABCD
- Codeforces Round #211 (Div. 2) ABCD
- Codeforces Round #208 (Div. 2) ABCD
- Codeforces Round #220 (Div. 2) ABCD
- Codeforces Round #222 (Div. 2) ABCD
- Codeforces Round #257 (Div. 2) ABCD
- Codeforces Round #258 (Div. 2)[ABCD]
- Codeforces Round #264 (Div. 2) | ABCD
- Codeforces Round #302 (Div. 2) (ABCD题解)
- Codeforces Round #250 (Div. 2) (ABCD题解)
- Codeforces Round #248 (Div. 2) (ABCD题解)
- Codeforces Round #249 (Div. 2) (ABCD题解)
- Codeforces Round #313 (Div. 2) (ABCD)
- Codeforces Round #Pi (Div. 2) (ABCD)
- Codeforces Round #Pi (Div. 2) ABCD
- 初来乍到
- 笔记:Java反射机制基础
- 深入了解java虚拟机-读书笔记
- Vases and Flowers
- ngrok安装使用
- Codeforces Round #428 (Div. 2) ABCD
- 浅谈算法和数据结构: 八 平衡查找树之2-3树
- 数据结构-二叉排序树
- HDU -- 6113 度度熊的01世界 【搜联通块 + 思维】
- Redis命令
- 基于人机交互设备测量用户情绪。
- UVA10820SendATable
- 【我很简单,请不要欺负我】模拟环境渗透详细记录
- 搭建Hadoop开发环境