http://codeforces.com/contest/896/problem/B
题意:交互题,有n格,每次给一个[1,c]的数字,回答填入的位置后再次给数字,要求在m轮内使n格填满且数列不递减。n,m>=2,1<=c<=1000,1<=n*[c/2]<=m<=1000。
思路:看到题目,我首先思考给出m>=nc/2 有什么用,一定能构造出序列,那么关键就在这里,然后自己写了几组数据思考了一下
考虑把小的数放在左边,大的数放在右边,每次如果能不破坏递增序列就尽量往中间放,发现当这个分割为c/2一定能得到长度为n的序列
对于左边替换的位置一定满足now<pre 才会替换 那么最多替换c/2次,假设每个位置都替换c/2次总共就需要(n-1)[c/2]+1,因为最后一个位置填上就不可能被替换
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define fi first
#define se second
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, int> LP;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 100;
const ll mod = 1e18+7;
const int base=131;
inline ll mul(ll x,ll y) { return (x*y-(ll)((long double)x*y/mod)*mod+mod)%mod;}
inline ll ksm(ll a,ll b) {ll ans=1;while(b){if(b&1)ans=mul(ans,a);a=mul(a,a),b>>=1;}return ans;}
ll n,m,x,y,cx,cy,flag;
ll a[N],b[N];
ll k,ans,cnt;
ll res[N],vis[N],mp[1005][1005];
ll pos[N];
vector<int> v[N];
P mx[N],mi[N];
int st[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int c;
cin>>n>>m>>c;
while(m--)
{
cin>>x;
if(x<=c/2)
{
for(int i=1;i<=n;i++)
{
if(a[i]==0)
{
a[i]=x;
cnt++;
cout<<i<<endl;
break;
}
else if(x<a[i])
{
a[i]=x;
cout<<i<<endl;
break;
}
}
}
else
{
for(int i=n;i>=1;i--)
{
if(!a[i])
{
a[i]=x;
cnt++;
cout<<i<<endl;
break;
}
else if(x>a[i])
{
a[i]=x;
cout<<i<<endl;
break;
}
}
}
//show2(cnt,m)
if(cnt==n) return 0;
}
}
/*
数据范围
是否爆int
空间大小
*/