• 朗讯杯


    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2718

    模拟 

      1 #include <iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 #include<algorithm>
      5 using namespace std;
      6 int w[25][25];
      7 int dis[4][2] = {1,0,0,-1,0,1,-1,0};
      8 int main()
      9 {
     10     int n,m,k,i,s1,s2,kk=0,d;
     11     while(cin>>n>>m>>k)
     12     {
     13         memset(w,0,sizeof(w));
     14         kk++;
     15         if(!n&&!m&&!k) break;
     16         for(i = 1; i <= k ; i++)
     17         {
     18             int x,y;
     19             cin>>x>>y;
     20             w[x][y] = 1;
     21         }
     22         cin>>s1>>s2;
     23         int num=0;
     24         if(s1==1)
     25         d = 0;
     26         else if(s2==1)
     27         d = 2;
     28         else if(s1==n)
     29         d = 3;
     30         else if(s2==m)
     31         d = 1;
     32         printf("Case %d: ",kk);
     33         int tx = s1,ty=s2,dd=d;
     34         num=1;
     35         while(1)
     36         {
     37             if(tx==1||ty==1||tx==n||ty==m)
     38             {
     39                 if(tx==1&&d==3)
     40                 {printf("%d %d %d
    ",tx,ty,num);break;}
     41                 else if(ty==1&&d==1)
     42                 {printf("%d %d %d
    ",tx,ty,num);break;}
     43                 else if(tx==n&&d==0)
     44                 {printf("%d %d %d
    ",tx,ty,num);break;}
     45                 else if(ty==m&&d==2)
     46                 {printf("%d %d %d
    ",tx,ty,num);break;}
     47             }
     48             int ox = dis[d][0]+tx;
     49             int oy = dis[d][1]+ty;
     50             if(w[ox][oy])
     51             {
     52                 if(d==0)
     53                 {
     54                     d = 1;
     55                     ox = dis[d][0]+tx;
     56                     oy = dis[d][1]+ty;
     57                     if(w[ox][oy])
     58                     {
     59                         d = 2;
     60                         ox = dis[d][0]+tx;
     61                         oy = dis[d][1]+ty;
     62                         if(w[ox][oy])
     63                         d = 3;
     64                     }
     65                 }
     66                 else if(d==1)
     67                 {
     68                     d = 3;
     69                     ox = dis[d][0]+tx;
     70                     oy = dis[d][1]+ty;
     71                     if(w[ox][oy])
     72                     {
     73                         d = 0;
     74                         ox = dis[d][0]+tx;
     75                         oy = dis[d][1]+ty;
     76                         if(w[ox][oy])
     77                         d = 2;
     78                     }
     79                 }
     80                 else if(d==3)
     81                 {
     82                     d = 2;
     83                     ox = dis[d][0]+tx;
     84                     oy = dis[d][1]+ty;
     85                     if(w[ox][oy])
     86                     {
     87                         d = 1;
     88                         ox = dis[d][0]+tx;
     89                         oy = dis[d][1]+ty;
     90                         if(w[ox][oy])
     91                         d = 0;
     92                     }
     93                 }
     94                 else
     95                 {
     96                     if(d==2)
     97                     {
     98                         d = 0;
     99                         ox = dis[d][0]+tx;
    100                         oy = dis[d][1]+ty;
    101                         if(w[ox][oy])
    102                         {
    103                             d = 3;
    104                             ox = dis[d][0]+tx;
    105                             oy = dis[d][1]+ty;
    106                             if(w[ox][oy])
    107                             d = 1;
    108                         }
    109                     }
    110                 }
    111             }
    112             else
    113             {
    114                 num++;
    115                 tx = ox;
    116                 ty = oy;
    117             }
    118         }
    119     }
    120     return 0;
    121 }
    122  
    123 
    124 
    125 
    126 /**************************************
    127     Problem id    : SDUT OJ 2718 
    128     User name    : shang 
    129     Result        : Accepted 
    130     Take Memory    : 472K 
    131     Take Time    : 0MS 
    132     Submit Time    : 2013-12-01 10:48:41  
    133 **************************************/
    View Code

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2719

    水题

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<queue>
     7 #include<vector>
     8 using namespace std;
     9 int ma[3][1010];
    10 int main()
    11 {
    12     int n,m,k,a,kk=0,i;
    13     while(cin>>n>>m>>k)
    14     {
    15         if(!n&&!m&&!k)
    16         break;
    17         memset(ma,0,sizeof(ma));
    18         kk++;
    19         for(i = 1; i <= k ; i++)
    20         {
    21             scanf("%d",&a);
    22             int k = a%n,t = 1,q = a;
    23             while(ma[t][k])
    24             {
    25                 int y = ma[t][k];
    26                 ma[t][k] = q;
    27                 q = y;
    28                 if(t==1)
    29                 {
    30                     t = 2;
    31                     k = y%m;
    32                 }
    33                 else
    34                 {
    35                     t = 1;
    36                     k = y%n;
    37                 }
    38             }
    39             ma[t][k] = q;
    40         }
    41         printf("Case %d:
    ",kk);
    42         for(i = 0 ; i < n ; i++)
    43         {
    44             if(ma[1][i])
    45             break;
    46         }
    47         if(i!=n)
    48         puts("Table 1");
    49         for(i = 0 ; i < n ; i++)
    50         {
    51             if(ma[1][i])
    52             printf("%d:%d
    ",i,ma[1][i]);
    53         }
    54         for(i = 0 ; i < m ; i++)
    55         {
    56             if(ma[2][i])
    57             break;
    58         }
    59         if(i!=m)
    60         puts("Table 2");
    61         for(i = 0 ; i < m ; i++)
    62         {
    63             if(ma[2][i])
    64             printf("%d:%d
    ",i,ma[2][i]);
    65         }
    66     }
    67     return 0;
    68 }
    69  
    70 
    71 
    72 
    73 /**************************************
    74     Problem id    : SDUT OJ 2719 
    75     User name    : shang 
    76     Result        : Accepted 
    77     Take Memory    : 500K 
    78     Take Time    : 0MS 
    79     Submit Time    : 2013-12-01 11:12:16  
    80 **************************************/
    View Code

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2721

    模拟 消行消列 bfs去元素

      1 #include <iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 #include<algorithm>
      5 #include<stdlib.h>
      6 #include<queue>
      7 #include<vector>
      8 
      9 using namespace std;
     10 int a[15][15],vis[15][15];
     11 int dis[4][2] = {0,1,0,-1,1,0,-1,0};
     12 struct node
     13 {
     14     int x,y;
     15 };
     16 void init()
     17 {
     18     int i,j;
     19     for(i = 2; i <= 12 ; i++)
     20     {
     21         for(j = 1; j <= 10 ; j++)
     22         if(a[i][j]&&!a[i-1][j])
     23         {
     24             int p = i-1;
     25             while(p>=1&&!a[p][j])
     26             p--;
     27             a[p+1][j] = a[i][j];
     28             a[i][j] = 0;
     29         }
     30     }
     31     for(i = 2; i <= 10 ; i++)
     32     {
     33         if(a[1][i]&&!a[1][i-1])
     34         {
     35             int p = i-1;
     36             while(p>=1&&!a[1][p])
     37             p--;
     38             int tt = 1;
     39             while(tt<=12&&a[tt][i])
     40             {
     41                 a[tt][p+1] = a[tt][i];
     42                 a[tt][i] = 0;
     43                 tt+=1;
     44             }
     45         }
     46     }
     47 }
     48 void bfs(int x,int y)
     49 {
     50     if(!a[x][y]) return ;
     51     memset(vis,0,sizeof(vis));
     52     node te,tt;
     53     te.x = x;
     54     te.y = y;
     55     queue<node>q;
     56     q.push(te);
     57     int num = 1;
     58     vis[x][y] = 1;
     59     while(!q.empty())
     60     {
     61         tt = q.front();
     62         q.pop();
     63         for(int i = 0 ; i < 4 ; i++)
     64         {
     65             int tx = tt.x+dis[i][0];
     66             int ty = tt.y+dis[i][1];
     67             if(tx>=1&&tx<=12&&ty>=1&&ty<=10&&!vis[tx][ty]&&a[tx][ty]==a[x][y])
     68             {
     69                 vis[tx][ty] = 1;
     70                 te.x = tx;
     71                 te.y = ty;
     72                 num++;
     73                 q.push(te);
     74             }
     75         }
     76     }
     77     int i,j;
     78     if(num>=3)
     79     {
     80         for(i = 1; i <= 12 ; i++)
     81         for(j = 1; j <= 10 ; j++)
     82         if(vis[i][j])
     83         a[i][j] = 0;
     84     }
     85     init();
     86 }
     87 int main()
     88 {
     89     int n,i,j,u;
     90     char c;
     91     while(cin>>n)
     92     {
     93         if(!n) break;
     94         for(i = 12; i >= 1 ; i--)
     95             for(j = 1 ;j <= 10 ; j++)
     96             {
     97                 cin>>c;
     98                 a[i][j] = c-'A'+1;
     99             }
    100         init();
    101         for(i = 1; i <= n ;i++)
    102         {
    103             cin>>c>>u;
    104             int v = c-'a'+1;
    105             bfs(u,v);
    106         }
    107         int ans = 0;
    108         for(i = 1; i <= 12 ; i++)
    109             for(j = 1; j <= 10 ; j++)
    110             if(a[i][j])
    111             ans++;
    112         cout<<ans<<endl;
    113     }
    114     return 0;
    115 }
    116  
    117 
    118 
    119 
    120 /**************************************
    121     Problem id    : SDUT OJ 2721 
    122     User name    : shang 
    123     Result        : Accepted 
    124     Take Memory    : 460K 
    125     Take Time    : 0MS 
    126     Submit Time    : 2013-12-01 12:50:28  
    127 **************************************/
    View Code

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2723

    枚举每条边 所存在除这条边以外的可以连接的路 就去掉这条边 水题

      1 #include <iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 #include<algorithm>
      5 #include<stdlib.h>
      6 #include<queue>
      7 #include<vector>
      8 #include<map>
      9 #include<string>
     10 using namespace std;
     11 char s1[210],s2[210],s[210][210];
     12 map<string,int>f;
     13 vector<int>ed[210];
     14 int w[210][210],vis[210],g;
     15 struct node
     16 {
     17     char s1[210],s2[210];
     18 }pp[40010],p[40010];
     19 int dfs(int u,int v)
     20 {
     21     queue<int>q;
     22     q.push(u);
     23     vis[u] = 1;
     24     while(!q.empty())
     25     {
     26         int k = q.front();
     27         q.pop();
     28         if(k==v) return 1;
     29         for(int i = 0; i < (int)ed[k].size() ; i++)
     30         {
     31             if(w[k][ed[k][i]]&&!vis[ed[k][i]])
     32             {
     33                 vis[ed[k][i]] = 1;
     34                 q.push(ed[k][i]);
     35             }
     36         }
     37     }
     38     return 0;
     39 }
     40 bool cmp(node a,node b)
     41 {
     42     if(strcmp(a.s1,b.s1)==0)
     43     return strcmp(a.s2,b.s2)<0;
     44     return strcmp(a.s1,b.s1)<0;
     45 }
     46 int main()
     47 {
     48     int n,kk=0,i,j;
     49     while(cin>>n)
     50     {
     51         if(!n) break;
     52         memset(w,0,sizeof(w));
     53         for(i = 0 ; i <= 200 ; i++)
     54         ed[i].clear();
     55         kk++;
     56         f.clear();
     57         g = 0;
     58         int oo=0;
     59         for(i = 1; i <= n ;i++)
     60         {
     61             cin>>s1>>s2;
     62             if(!f[s1])
     63             {
     64                 f[s1] = ++g;
     65                 strcpy(s[g],s1);
     66             }
     67             if(!f[s2]) {f[s2] = ++g;strcpy(s[g],s2);}
     68             w[f[s1]][f[s2]] = 1;
     69             ed[f[s1]].push_back(f[s2]);
     70         }
     71         int o = 0;
     72         for(i = 1; i <= g ; i++)
     73         {
     74             for(j = 0 ; j< (int)ed[i].size() ; j++)
     75             {
     76                 int v = ed[i][j];
     77                 w[i][v] = 0;
     78                 memset(vis,0,sizeof(vis));
     79                 if(dfs(i,v))
     80                 {
     81                     o++;
     82                     strcpy(p[o].s1,s[i]);
     83                     strcpy(p[o].s2,s[v]);
     84                 }
     85                 else
     86                 w[i][v] = 1;
     87             }
     88         }
     89         sort(p+1,p+o+1,cmp);
     90         printf("Case %d: ",kk);
     91         if(o!=0)
     92         {
     93             oo++;
     94             pp[oo] = p[1];
     95         }
     96         for(i = 2 ; i <= o ; i++)
     97         {
     98             if(strcmp(p[i].s1,p[i-1].s1)==0&&strcmp(p[i].s2,p[i-1].s2)==0)
     99             continue;
    100             oo++;
    101             pp[oo] = p[i];
    102         }
    103         printf("%d",oo);
    104         for(i = 1 ; i < oo ; i++)
    105         printf(" %s,%s",pp[i].s1,pp[i].s2);
    106         if(oo!=0)
    107         printf(" %s,%s",pp[oo].s1,pp[oo].s2);
    108         puts("");
    109     }
    110     return 0;
    111 }
    112  
    113 
    114 
    115 
    116 /**************************************
    117     Problem id    : SDUT OJ 2723 
    118     User name    : shang 
    119     Result        : Accepted 
    120     Take Memory    : 17068K 
    121     Take Time    : 520MS 
    122     Submit Time    : 2013-12-01 14:12:31  
    123 **************************************/
    View Code
  • 相关阅读:
    C调用C++的动态库
    记“gorm查询没报错,但结果为空”的解决
    Android学习之路(一) Android Studio创建项目
    Windows程序消息机制浅析
    2021.5.1 学习小目标
    微信测试流程
    mysql使用正则表达式匹配中文所遇到的问题
    关于mysql的distinct用法
    一次性能测试的网络层面总结
    mongodb中直接根据某个字段更新另外一个字段值
  • 原文地址:https://www.cnblogs.com/shangyu/p/3452855.html
Copyright © 2020-2023  润新知