首页 > 代码库 > URAL 1995 Illegal spices

URAL 1995 Illegal spices

构造。

前$n-k$个都是$1$,最后$k$个进行构造,首先选择填与上一个数字一样,如果不可行,那么这一格的值$+1$。

#include<map>#include<set>#include<ctime>#include<cmath>#include<queue>#include<string>#include<vector>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<functional>using namespace std;#define ms(x,y) memset(x,y,sizeof(x))#define rep(i,j,k) for(int i=j;i<=k;i++)#define per(i,j,k) for(int i=j;i>=k;i--)#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])#define inone(x) scanf("%d",&x)#define intwo(x,y) scanf("%d%d",&x,&y)#define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)#define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p)#define lson x<<1,l,mid#define rson x<<1|1,mid+1,r#define mp(i,j) make_pair(i,j)#define ft first#define sd secondtypedef long long LL;typedef pair<int, int> pii;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 1e6 + 10;const int M = 1e4 + 1;const double eps = 1e-10;int T, n ,m, k, p;int c[100010];int a[100010];long long s;void update(int x,int val){    while(x<=100000)    {        c[x]=c[x]+val;        x=x+low(x);    }}int sum(int x){    int res=0;    while(x>0)    {        res=res+c[x];        x=x-low(x);    }    return res;}int main(){    while(~scanf("%d%d",&n,&k))    {        scanf("%d",&p); s=0;        for(int i=1;i<=n-k;i++) a[i]=1;        int now=2,x=0,cnt=n-k;        for(int i=n-k+1;i<=n;i++)        {            a[i] = now;            if(cnt*100>=p*(i-1))            {                x++;            }            else            {                now++;                cnt+=x;                a[i]=now;                x=1;            }        }        for(int i=1;i<=n;i++) s=s+(long long) a[i];        printf("%lld\n",s);        for(int i=1;i<=n;i++)        {            printf("%d",a[i]);            if(i<n) printf(" ");            else printf("\n");        }    }    return 0;}

 

URAL 1995 Illegal spices