• 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)


    题目链接:

      http://codeforces.com/gym/100825

    题目大意:

      栅栏密码。给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密文字符串S,长度为N*N

      每次将这个矩阵顺时针旋转90°,把矩阵中空格对应的位置按照从上到下从左到右的顺序依次填充上密文字符,求最终这个密文字符能否填满N*N的矩阵,能按顺序输出得到的答案,不能输出"invalid grille"

    题目思路:

      【模拟】

      直接模拟即可。旋转的坐标公式很好推。

      1 //
      2 //by coolxxx
      3 //#include<bits/stdc++.h>
      4 #include<iostream>
      5 #include<algorithm>
      6 #include<string>
      7 #include<iomanip>
      8 #include<map>
      9 #include<stack>
     10 #include<queue>
     11 #include<set>
     12 #include<bitset>
     13 #include<memory.h>
     14 #include<time.h>
     15 #include<stdio.h>
     16 #include<stdlib.h>
     17 #include<string.h>
     18 //#include<stdbool.h>
     19 #include<math.h>
     20 #define min(a,b) ((a)<(b)?(a):(b))
     21 #define max(a,b) ((a)>(b)?(a):(b))
     22 #define abs(a) ((a)>0?(a):(-(a)))
     23 #define lowbit(a) (a&(-a))
     24 #define sqr(a) ((a)*(a))
     25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
     26 #define mem(a,b) memset(a,b,sizeof(a))
     27 #define eps (1e-10)
     28 #define J 10000
     29 #define mod 1000000007
     30 #define MAX 0x7f7f7f7f
     31 #define PI 3.14159265358979323
     32 #define N 14
     33 #define M 104
     34 using namespace std;
     35 typedef long long LL;
     36 double anss;
     37 LL aans;
     38 int cas,cass;
     39 int n,m,lll,ans;
     40 struct xxx
     41 {
     42     int x,y;
     43 }q[M];
     44 char s[N][N],a[N][N];
     45 char c[M];
     46 bool cmp(xxx aa,xxx bb)
     47 {
     48     if(aa.x!=bb.x)return aa.x<bb.x;
     49     return aa.y<bb.y;
     50 }
     51 void print()
     52 {
     53     int i,j;
     54     for(i=0;i<n;i++)
     55         printf("%s",a[i]);
     56     puts("");
     57 }
     58 bool work()
     59 {
     60     int i,j,k;
     61     for(k=1;k<4;k++)
     62     {
     63         for(i=1;i<=m;i++)
     64         {
     65             j=q[i].x;
     66             q[i].x=q[i].y;
     67             q[i].y=n-j-1;
     68         }
     69         sort(q+1,q+m+1,cmp);
     70         for(i=1;i<=m;i++)
     71         {
     72             if(a[q[i].x][q[i].y])return 0;
     73             a[q[i].x][q[i].y]=c[cas++];
     74         }
     75     }
     76     for(i=0;i<n;i++)
     77         for(j=0;j<n;j++)
     78             if(!a[i][j])return 0;
     79     return 1;
     80 }
     81 int main()
     82 {
     83     #ifndef ONLINE_JUDGE
     84     freopen("1.txt","r",stdin);
     85 //    freopen("2.txt","w",stdout);
     86     #endif
     87     int i,j,k;
     88     int x,y,z;
     89 //    init();
     90 //    for(scanf("%d",&cass);cass;cass--)
     91 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
     92 //    while(~scanf("%s",s))
     93     while(~scanf("%d",&n))
     94     {
     95         mem(a,0);cas=0;m=0;
     96         for(i=0;i<n;i++)
     97             scanf("%s",s[i]);
     98         scanf("%s",c);
     99         if(n==1)
    100         {
    101             puts("invalid grille");
    102             continue;
    103         }
    104         for(i=0;i<n;i++)
    105             for(j=0;j<n;j++)
    106                 if(s[i][j]=='.')
    107                 {
    108                     a[i][j]=c[cas++];
    109                     q[++m].x=i,q[m].y=j;
    110                 }
    111         if(!work())puts("invalid grille");
    112         else print();
    113     }
    114     return 0;
    115 }
    116 /*
    117 //
    118 
    119 //
    120 */
    View Code
  • 相关阅读:
    表单验证
    obs 之 OBSObj
    rtmp流媒体协议分析(h264、aac)
    lintcode 508.Wiggle Sort
    SVN备份批处理文件
    防火墙没关导致 ORA-12541: TNS: 无监听程序
    [转]window10系统安装oracle11g时遇到INS-13001环境不满足最低要求
    关键驱动因素、约束和浮动因素
    C#之虚函数 非常清晰全面的讲解
    今天有个朋友问我抽象方法和接口的区别,为了解释清楚这个事情,我在网上看到一篇文章讲的非常好给大家分享一下,也感谢原作者的付出
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5850532.html
Copyright © 2020-2023  润新知