Codeforces Round #449 B. Ithea Plays With Chtholly
http://codeforces.com/contest/896/problem/B
题意:
交互题
n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m
最后填出一个单调非降序列,输出每次填的位置
<=c/2:
从左开始扫描,遇到空位 或 比原数更优(<原数)就放
>c/2:
从右开始扫描,遇到空位 或 比原数更优(>原数)就放
以<=c/2为例:
空位就放,<原数就覆盖,>=原数就往后扫
这样每个位置最多只会被覆盖c/2次,(c/2 ~1 各覆盖一次)
又因为 m>=n*ceil(c/2)
所以最后一定有解
#include<cstdio> using namespace std; int a[1001]; int main() { int n,m,c,x; scanf("%d%d%d",&n,&m,&c); int mid=c>>1; int sum=0; while(m--) { scanf("%d",&x); if(x<=mid) { for(int i=1;;++i) { if(!a[i]) { a[i]=x; sum++; printf("%d\n",i); break; } else if(a[i]>x) { a[i]=x; printf("%d\n",i); break; } } } else { for(int i=n;;--i) { if(!a[i]) { a[i]=x; sum++; printf("%d\n",i); break; } else if(x>a[i]) { a[i]=x; printf("%d\n",i); break; } } } fflush(stdout); if(sum==n) return 0; } }


,
means
rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process.
浙公网安备 33010602011771号