2017.12.28

上午学了网络流:
http://blog.csdn.net/a1035719430/article/details/78926269

下午打了模拟赛:
http://blog.csdn.net/a1035719430/article/details/78926233

外加切了几道水题。
1、判断数独
数独是一款智力游戏,现给你一个数独,并需要你验证是否符合规则。 具体规则如下: 每一行都用到1,2,3,4,5,6,7,8,9,位置不限, 每一列都用到1,2,3,4,5,6,7,8,9,位置不限, 每3×3的格子(共九个这样的格子)都用到1,2,3,4,5,6,7,8,9,位置不限, 游戏的过程就是用1,2,3,4,5,6,7,8,9填充空白,并要求满足每行、每列、每个九宫格都用到1,2,3,4,5,6,7,8,9。
输入格式
输入n个数独,你来验证它是否违反规则. 第一行为数独个数, 第二行为第一个数独,之后为第二个,至第n个. 每个数独之间有一个空行

输出格式
若正确则输出”Right”若不正确则输出”Wrong” 输出一个换一行

样例数据
input

2
5 8 1 4 9 3 7 6 2
9 6 3 7 1 2 5 8 4
2 7 4 8 6 5 9 3 1
1 2 9 5 4 6 3 7 8
4 3 6 1 8 7 2 9 5
7 5 8 3 2 9 1 4 6
8 9 2 6 7 1 4 5 3
6 1 5 9 3 4 8 2 7
3 4 7 2 5 8 6 1 9

1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8
output

Right
Wrong
数据规模与约定
1<=n<=20 (输入的数独个数) 不论输入的数独是错误的还是正确的,数据都保证每个数在1-9之间,即只会出现因为有相同的数而导致违反规则,而不会因为数字超出了1-9的范围而违反规则.

时间限制:1s1s
空间限制:256MB

大力循环做是最简单的方法?

#include<bits/stdc++.h>
using namespace std;
int n,f[10][10];
int read() 
{ 
    bool flag=true; 
    int num=0;char c=getchar(); 
    for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=false; 
    for(;c>='0'&&c<='9';c=getchar()) 
    num=(num<<3)+(num<<1)+c-48; 
    if(flag) return num; 
     else return -num; 
} 
void work()
{
    n=read();
    bool check=true;
    for(int a=1;a<=n;++a)
     {
      for(int x=1;x<=9;++x)
       for(int y=1;y<=9;++y)    
        f[x][y]=read();
      bitset<10>sum(0); 
      check=true;
      for(int i=1;i<=9;++i)
       { 
        sum.reset();
        for(int j=1;j<=9;++j)
         if(sum[f[i][j]]==0) sum[f[i][j]]=1;
          else {check=false;break;}
        if(!check) break;
       }
       if(!check) {printf("Wrong\n");continue;}

      for(int i=1;i<=9;++i)
       {
        sum.reset();
        for(int j=1;j<=9;++j)
         if(sum[f[j][i]]==0) sum[f[j][i]]=1;
          else {check=false;break;}
        if(!check) break; 
       }
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=1;i<=3;++i) {for(int j=1;j<=3;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=4;i<=6;++i) {for(int j=1;j<=3;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=7;i<=9;++i) {for(int j=1;j<=3;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=1;i<=3;++i) {for(int j=4;j<=6;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=4;i<=6;++i) {for(int j=4;j<=6;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=7;i<=9;++i) {for(int j=4;j<=6;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=1;i<=3;++i) {for(int j=7;j<=9;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=4;i<=6;++i) {for(int j=7;j<=9;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;}

      sum.reset();
      for(int i=7;i<=9;++i) {for(int j=7;j<=9;++j) if(sum[f[i][j]]==0) sum[f[i][j]]=true; else {check=false;break;} if(!check) break;}
      if(!check) {printf("Wrong\n");continue;} 
      printf("Right\n");
     }
    return;
}
int main()
{ 
    work();
    return 0;
}  

2.3、网络流模板题:略去(见另一博客)
4、
题目描述
N(3<=N<=200)头奶牛要办一个新年晚会。每头牛都会烧几道菜。一共有D(5<=D<=100)道不同的菜肴。每道菜都可以用一个1到D之间的数来表示。 晚会的主办者希望能尽量多的菜肴被带到晚会,但是每道菜的数目又给出了限制。每头奶牛可以带K(1<=K<=5)道菜,但是必须是各不相同的(例如,一头牛不能带三块馅饼,但是可以带上一块馅饼,一份面包,和一些美味的桔子酱苜蓿)。那么,究竟有多少菜可以被带来晚会呢?

输入格式
第一行包括三个整数N,K和D。 第二行有D个非负整数,表示每种菜可以带到晚会上的数目限制。 第三行到第N+2行,每行包括一个整数Z,表示一头牛可以准备的菜的道数;之后Z个整数,表示菜的标号,首先是第一种菜,然后是第二种菜,以此类推。

输出格式
仅一行一个整数,表示可以带到晚会上的最多的菜的数目。

input

4 3 5
2 2 2 2 3
4 1 2 3 4
4 2 3 4 5
3 1 2 4
3 1 2 3
output

9
数据规模与约定
时间限制:1s 空间限制:256MB

这题建图比较方便,确定一个根和所有的牛连边,限制为一个牛可以带的食物数,牛和可以选的食物连边,限制为1,食物和终点连边,限制为第二行输入。跑一遍最大流即可。

猜你喜欢

转载自blog.csdn.net/a1035719430/article/details/78926384
今日推荐