国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Codeforces Round #390 (Div. 2)

2019-11-08 18:23:41
字體:
來源:轉載
供稿:網友
/*Codeforces Round #390 (Div. 2)時間: 2017/02/16A題題意:將集合分成幾個小集合,要求小集合的和不為0.題解:遍歷過去,一直到不滿足集合并數字非0前生成一個集合*/#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>#include <queue>using namespace std;const int INF = 0x3f3f3f3f;const int N = 110;int a[N];int rel[N],rer[N];int main(){    int n;    while(~scanf("%d",&n))    {        int flag = 0;        for(int i = 1; i <= n; i++)        {            scanf("%d",&a[i]);            if(a[i])                flag = 1;        }        if(!flag)            puts("NO");        else        {            puts("YES");            int r = 1,l = 1;            int sum = 0;            int k = 0;            while(r <= n)            {                sum += a[r];                if(!sum && a[r])                {                    rel[k] = l;                    rer[k++] = r-1;                    l = r;                }                else                    r++;            }            rel[k] = l;            rer[k++] = r-1;            PRintf("%d/n",k);            for(int i = 0; i < k; i++)                printf("%d %d/n",rel[i],rer[i]);        }    }    return 0;}

/*Codeforces Round #390 (Div. 2)時間: 2017/02/16B題題意:給你一個4*4的棋盤,誰先連成三子誰贏,‘x’為先手下的棋,‘o’為后手下的棋,‘.’為空,問先手下一步能不贏題解:將枚舉每個空格位置,判斷位置可行性*/#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>#include <queue>using namespace std;const int INF = 0x3f3f3f3f;const int N = 10;int p[N][N];bool hefa(int x,int y){    if(x >= 0 && x <= 3 && y >= 0 && y <= 3)        return true;    return false;}bool pan(int x,int y){    if(hefa(x-1,y) && hefa(x-2,y) && p[x-1][y] == 1 && p[x-2][y] == 1)        return true;    if(hefa(x-1,y-1) && hefa(x-2,y-2) && p[x-1][y-1] == 1 && p[x-2][y-2] == 1)        return true;    if(hefa(x+1,y) && hefa(x+2,y) && p[x+1][y] == 1 && p[x+2][y] == 1)        return true;    if(hefa(x+1,y+1) && hefa(x+2,y+2) && p[x+1][y+1] == 1 && p[x+2][y+2] == 1)        return true;    if(hefa(x-1,y-1) && hefa(x+1,y+1) && p[x-1][y-1] == 1 && p[x+1][y+1] == 1)        return true;    if(hefa(x-1,y) && hefa(x+1,y) && p[x-1][y] == 1 && p[x+1][y] == 1)        return true;    if(hefa(x,y-1) && hefa(x,y-2) && p[x][y-1] == 1 && p[x][y-2] == 1)        return true;    if(hefa(x-1,y+1) && hefa(x-2,y+2) && p[x-1][y+1] == 1 && p[x-2][y+2] == 1)        return true;    if(hefa(x,y+1) && hefa(x,y+2) && p[x][y+1] == 1 && p[x][y+2] == 1)        return true;    if(hefa(x+1,y-1) && hefa(x+2,y-2) && p[x+1][y-1] == 1 && p[x+2][y-2] == 1)        return true;    if(hefa(x+1,y-1) && hefa(x-1,y+1) && p[x+1][y-1] == 1 && p[x-1][y+1] == 1)        return true;    if(hefa(x,y-1) && hefa(x,y+1) && p[x][y-1] == 1 && p[x][y+1] == 1)        return true;    return false;}int main(){    char s[N];    while(~scanf("%s",s))    {        int a;        for(int j = 0; j < 4; j++)        {            if(s[j] == 'x')                a = 1;            else if(s[j] == '.')                a = 0;            else                a = 2;            p[0][j] = a;        }        for(int i = 1; i < 4; i++)        {            scanf("%s",s);            for(int j = 0; j < 4; j++)            {                if(s[j] == 'x')                    a = 1;                else if(s[j] == '.')                    a = 0;                else                    a = 2;                p[i][j] = a;            }        }        int flag = 0;        for(int i = 0; i < 4; i++)        {            for(int j = 0; j < 4; j++)            {                //printf("%d ",p[i][j]);                if(!p[i][j] && pan(i,j))                {                    flag = 1;                    break;                }            }            //puts("");            if(flag)                break;        }        if(flag)            puts("YES");        else            puts("NO");    }    return 0;}

/*Codeforces Round #390 (Div. 2)時間: 2017/02/16D題題意:給你n個具有范圍的禮券,選擇k個禮券,要求k個禮券交叉包含的范圍最大,輸出范圍大小和選擇的禮券。題解:要選k個禮券維護最大,我們要使禮券交叉左極限小,右極限大。這樣看來將禮券按左極限排序,然后右極限用優先隊列維護即可。*/#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>#include <queue>using namespace std;const int INF = 0x3f3f3f3f;const int N = 300010;struct asd{    int l,r,id;    friend bool Operator< (asd n1,asd n2)    {        return n1.r > n2.r;    }}a[N];bool cmp(asd n1,asd n2){    return n1.l < n2.l;}int main(){    int n,k;    while(~scanf("%d%d",&n,&k))    {        for(int i = 1; i <= n; i++)        {            scanf("%d%d",&a[i].l,&a[i].r);            a[i].id = i;        }        sort(a+1,a+n+1,cmp);        priority_queue<asd> q;        int ans = 0,res = 0;        for(int i = 1; i <= n; i++)        {            asd temp;            if(!q.empty())                temp = q.top();            if(q.size() < k)                q.push(a[i]);            else if(temp.r < a[i].r)            {                q.pop();                q.push(a[i]);            }            if(q.size() == k)            {                temp = q.top();                if(temp.r-a[i].l+1 > ans)                {                    ans = temp.r-a[i].l+1;                    res = i;                }            }        }        printf("%d/n",ans);        if(ans)        {            int id = 0;            for(int i = 1; i <= res && id < k; i++)            {                if(a[res].l+ans-1 <= a[i].r)                {                    printf("%d ",a[i].id);                    id++;                }            }        }        else        {            for(int i = 1; i <= k; i++)                printf("%d ",i);        }        puts("");    }    return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 章丘市| 阿巴嘎旗| 绩溪县| 温州市| 吉首市| 哈尔滨市| 辽源市| 项城市| 阿克苏市| 达拉特旗| 阿城市| 团风县| 兴和县| 舒兰市| 福清市| 佛冈县| 沾化县| 清丰县| 逊克县| 彭阳县| 孝感市| 长海县| 措美县| 建瓯市| 台江县| 南通市| 江陵县| 天水市| 绍兴市| 临武县| 丁青县| 横山县| 扶风县| 大新县| 江阴市| 仁寿县| 康乐县| 舟山市| 姜堰市| 若尔盖县| 分宜县|