Codeforces 1261 E Not Same —— 想法

This way

题意:

给你n个数,每次你能选择一些位置,使得这些位置上的数-1,如果一个位置的数=0了,就不能再选这个位置。现在要让你每次选的位置的集合不能重复,问你每次每个位置是否被选择。

题解:

它的想法和我的想法其实差不多,,但是我的还是不行,我是想排序后左下角到右上角的对角线上都是0,用其他位置上的1弥补过来。但是这样的话上面和下面可能会有地方重复,我想不太出来用什么方法解决。看他们写的代码之后发现,其实只需要每个位置从i开始往上放即可,这样就不会出现重复了,因为是从大到小排序的,所以对角线上方是1聚集在前面,下方是1聚集在后面,有一条线分开。。自己意会一下吧

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
struct node
{
    int v,id;
    int b[N];
    bool operator< (const node& a)const{
        return v>a.v;
    }
}a[N];
bool cmp(node x,node y){
    return x.id<y.id;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i].v),a[i].id=i;
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=a[i].v;j++){
            a[i].b[(i+j-1-1)%(n+1)+1]=1;
        }
    }
    printf("%d\n",n+1);
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n+1;i++){
        for(int j=1;j<=n;j++)
            printf("%d",a[j].b[i]);
        printf("\n");
    }
    return 0;
}

发布了530 篇原创文章 · 获赞 31 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/tianyizhicheng/article/details/104240412