>  기사  >  웹 프론트엔드  >  Codeforces Round #252 (Div. 2)-C,D_html/css_WEB-ITnose

Codeforces Round #252 (Div. 2)-C,D_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-24 12:03:00879검색

C题就是一个简单的模拟,首先给每个人两个。然后把剩下的都给一个人就好了。

给的时候蛇形给。

#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<vector>#include<queue>using namespace std;#define LL __int64#define maxn 330000int main(){    int n,m,k;    while(~scanf("%d%d%d",&n,&m,&k))    {        int leap=1;        int stx=1;        int sty=1;        int ms=n*m-(k*2)+2;        printf("%d",ms);        while(ms--)        {            printf(" %d %d",stx,sty);            sty+=leap;            if(stym)            {                if(stym)sty=m;                stx++;leap=-leap;            }        }        coutm)            {                if(stym)sty=m;                stx++;leap=-leap;            }            printf("%d %d\n",stx,sty);            sty+=leap;            if(stym)            {                if(stym)sty=m;                stx++;leap=-leap;            }        }    }    return 0;}</queue></vector></iostream></algorithm></string.h></stdio.h>
D:首先根据环,把每一个环分成一组。记录下此时至少需要交换all次,才能回归到恒等排列。

1,如果all大于p。那么我们就应该把all减少。

对于一个环,任意两个点交换都可以把环分成两份,all-1;

对于每次减少,我们寻找环的最小值最小的环,然后在这个环中寻找最小值,然后交换这两个点。

2,如果all小于p。那么我们应该把all增大。

那么我们就可以把1号节点和任意节点交换,来达到增大all的目的。

注意,1号节点不和本身的环交换。并且1号节点和任意一个环只交换一次。

#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<vector>#include<queue>using namespace std;#define LL __int64#define maxn 3300int a[maxn];int b[maxn];int vis[maxn];vector<int>vec;vector >ans;struct list{    int x,y;} node;vector<list>pr;bool cmp(vector<int>a,vector<int>b){    return a[0]<b listt int x index l friend bool operator return a.x>b.x;    }}tt;priority_queue<listt>que;int main(){    int n,m;    while(~scanf("%d",&n))    {        for(int i=1; i0; i++)                {                    if(b[i]==i)                    {                        all--;                        node.y=i;                        pr.push_back(node);                    }                    if(ans.size()>j&&ans[j][0]==i)                    {                        all--;                        node.y=i;                        j++;                        pr.push_back(node);                    }                }            }        }        else        {            int qian=all;            all=all-m;            int i=0;            while(!que.empty())que.pop();            for(i=0;i<ans.size tt.index="i;" tt.x="ans[i][0];" que.push while tt="que.top();" que.pop i="tt.index;" node.x="ans[i][0];" int minn="9999;" st="0;" for j="1;j<ans[i].size()&&all">0;j++)                {                    if(minn>ans[i][j])                    {                        minn=ans[i][j];                        st=j;                    }                }                node.y=minn;                all--;                pr.push_back(node);                vec.clear();                minn=9999;                vec.push_back(ans[i][st]);                for(int j=1;j<st vec.push_back if>1)                {                    ans.push_back(vec);                    tt.index=ans.size()-1;                    tt.x=vec[0];                    que.push(tt);                }                vec.clear();                vec.push_back(ans[i][0]);                for(int j=st+1;j<ans vec.push_back if>1)                {                    ans[i]=vec;                    tt.index=i;                    tt.x=vec[0];                    que.push(tt);                }                i++;            }        }        cout  <br>  <br>  <p></p>  <p><br> </p>  <p><br> </p>  <p><br> </p>  <p><br> </p>  <p><br> </p>  <p><br> </p>  <p><br> </p> </ans></st></ans.size></listt></b></int></int></list></int></queue></vector></iostream></algorithm></string.h></stdio.h>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.