首页 >web前端 >html教程 >Codeforces Round #277.5 (Div. 2) 解题报告_html/css_WEB-ITnose

Codeforces Round #277.5 (Div. 2) 解题报告_html/css_WEB-ITnose

WBOY
WBOY原创
2016-06-24 11:53:37851浏览

还是只会4道。。sad。。。

A:SwapSort

用一个数组存储排好序之后。然后从头开始依次将需要交换的与本来应该在这个位置的交换,最多交换n-1次。

代码如下;

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int a[4000], b[4000], c[4000], d[4000];int main(){    int i, j, n, pos, cnt;    while(scanf("%d",&n)!=EOF)    {        cnt=0;        for(i=0;i<n scanf b sort for if pos="j;" break swap c printf return>  <br> B:  BerSU Ball  <p></p>  <p>二分图最大匹配裸题。</p>  <p>代码如下:</p>  <p></p>  <pre name="code" class="sycode">#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int link[200], vis[200], n, m, a[200], b[200];int head[200], cnt;struct node{    int u, v, next;}edge[100000];void add(int u, int v){    edge[cnt].v=v;    edge[cnt].next=head[u];    head[u]=cnt++;}int dfs(int u){    int i;    for(i=head[u];i!=-1;i=edge[i].next)    {        int v=edge[i].v;        if(!vis[v])        {            vis[v]=1;            if(link[v]==-1||dfs(link[v]))            {                link[v]=u;                return 1;            }        }    }    return 0;}void hungary(){    int i, ans=0;    memset(link,-1,sizeof(link));    for(i=0;i<n memset if ans printf main int i j while for scanf cnt="0;" add hungary return>  <br> C:  Given Length and Sum of Digits...  <p></p>  <p>贪心水题。</p>  <p>按照顺序依次填充。</p>  <p>代码如下:</p>  <p></p>  <pre name="code" class="sycode">#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;int a[1000], b[1000];int main(){    int m, s, i, j, x;    while(scanf("%d%d",&m,&s)!=EOF)    {        if(m*9<s printf continue if else x="s-1;" for i>=2; i--)        {            if(x>=9)            {                a[i]=9;                x-=9;            }            else if(x>=0&&x=9)            {                b[i]=9;                x-=9;            }            else if(x>=0&&x  <br> D:  Unbearable Controversy of Being  </s><p></p>  <p>枚举起点,分别进行BFS找到距离为2的点,然后记录到达这个点的次数,若次数大于2,说明存在,根据组合数来求解。</p>  <p>代码如下:</p>  <p></p>  <pre name="code" class="sycode">#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64LL vis[4000], ans;int head[4000], cnt, n;struct node{    int u, v, next;}edge[50000];void add(int u,int v){    edge[cnt].v=v;    edge[cnt].next=head[u];    head[u]=cnt++;}void bfs(int x){    int i;    queue<int>q;    for(i=head[x];i!=-1;i=edge[i].next)    {        q.push(edge[i].v);    }    while(!q.empty())    {        int u=q.front();        q.pop();        for(i=head[u];i!=-1;i=edge[i].next)        {            int v=edge[i].v;            if(v!=x)                vis[v]++;        }    }    for(i=1;i=2)            ans+=vis[i]*(vis[i]-1)/2;    }}int main(){    int m, i, j, u, v;    scanf("%d%d",&n,&m);    ans=0;    memset(head,-1,sizeof(head));    cnt=0;    while(m--)    {        scanf("%d%d",&u,&v);        add(u,v);    }    for(i=1;i  <br>  <br>  <p></p> </int></algorithm></set></map></queue></ctype.h></math.h></stdlib.h></cstring></string></cstdio></iostream>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn