zoukankan      html  css  js  c++  java
  • Codeforces 758B Blown Garland

    题目链接:http://codeforces.com/contest/758/problem/B

    题意:一个原先为4色环的链子少了部分,要你找出死的最少的一种可能,各输出四种颜色的死了多少。

    分析:就是要找出这个链子是那个部分。那么就有4!种可能。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 char str[24][5] =
     6 {
     7     "BGRY",
     8     "BGYR",
     9     "BRGY",
    10     "BRYG",
    11     "BYGR",
    12     "BYRG",
    13     "GBRY",
    14     "GBYR",
    15     "GRBY",
    16     "GRYB",
    17     "GYBR",
    18     "GYRB",
    19     "RBGY",
    20     "RBYG",
    21     "RGBY",
    22     "RGYB",
    23     "RYBG",
    24     "RYGB",
    25     "YBGR",
    26     "YBRG",
    27     "YGBR",
    28     "YGRB",
    29     "YRBG",
    30     "YRGB",
    31 };
    32 
    33 int cnt[24];
    34 int color[4];
    35 
    36 int main()
    37 {
    38     char cmp[110];
    39     scanf("%s",cmp);
    40     int len = strlen(cmp);
    41     for(int i=0;i<len;i++) {
    42         for(int j=0;j<24;j++) {
    43             if(str[j][i%4]==cmp[i])
    44                 cnt[j]++;
    45         }
    46     }
    47 
    48     int id;
    49     int tmp = -1;
    50     for(int i=0;i<24;i++) {
    51         if(tmp<cnt[i])
    52         {
    53             tmp = cnt[i];
    54             id = i;
    55         }
    56     }
    57 
    58     for(int i=0;i<len;i++)
    59         if(str[id][i%4]!=cmp[i])
    60             color[i%4] ++;
    61 
    62     int Rid;
    63     for(int r=0;r<4;r++)
    64     {
    65         if(str[id][r]=='R')
    66             Rid = r;
    67     }
    68 
    69     int Bid;
    70     for(int r=0;r<4;r++)
    71     {
    72         if(str[id][r]=='B')
    73             Bid = r;
    74     }
    75 
    76     int Yid;
    77     for(int r=0;r<4;r++)
    78     {
    79         if(str[id][r]=='Y')
    80             Yid = r;
    81     }
    82 
    83     int Gid;
    84     for(int r=0;r<4;r++)
    85     {
    86         if(str[id][r]=='G')
    87             Gid = r;
    88     }
    89 
    90     printf("%d %d %d %d
    ",color[Rid],color[Bid],color[Yid],color[Gid]);
    91 
    92 
    93     return 0;
    94 }
  • 相关阅读:
    租房子查询练习
    投票练习题
    多条件查询
    查询
    练习---新闻界面
    mysql增删改处理
    挖宝游戏
    mysql数据访问
    练习···表格
    类的使用
  • 原文地址:https://www.cnblogs.com/TreeDream/p/6322686.html
Copyright © 2011-2022 走看看