zoukankan      html  css  js  c++  java
  • Codeforces Round #234 (Div. 2) 解题报告

    Problem A Inna and Choose Options

    题意:水题

    代码如下:

     1 /**************************************************
     2  * Author     : xiaohao Z
     3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
     4  * Last modified : 2014-03-05 23:13
     5  * Filename     : Codeforce_234_2_A.cpp
     6  * Description     : 
     7  * ************************************************/
     8 
     9 #include <iostream>
    10 #include <cstdio>
    11 #include <cstring>
    12 #include <cstdlib>
    13 #include <cmath>
    14 #include <algorithm>
    15 #include <queue>
    16 #include <stack>
    17 #include <vector>
    18 #include <set>
    19 #include <map>
    20 #define MP(a, b) make_pair(a, b)
    21 #define PB(a) push_back(a)
    22 
    23 using namespace std;
    24 typedef long long ll;
    25 typedef pair<int, int> pii;
    26 typedef pair<unsigned int,unsigned int> puu;
    27 typedef pair<int, double> pid;
    28 typedef pair<ll, int> pli;
    29 typedef pair<int, ll> pil;
    30 
    31 const int INF = 0x3f3f3f3f;
    32 const double eps = 1E-6;
    33 int mp[20][20];
    34 vector<pii> p;
    35 string str;
    36 
    37 void debug(int a, int b){
    38     for(int i=0; i<a; i++){
    39         for(int j=0; j<b; j++){
    40             cout << mp[i][j] << ' ';
    41         }cout << endl;
    42     }cout << endl;
    43 }
    44 
    45 bool calc(int a, int b){
    46     for(int i=0; i<a; i++){
    47         for(int j=0; j<b; j++){
    48             if(str[i*b+j] == 'X') mp[i][j] = 1;
    49             else mp[i][j] = 0;
    50         }
    51     }
    52     for(int i=0; i<b; i++){
    53         int f = 1;
    54         for(int j=0; j<a; j++){
    55             if(mp[j][i] == 0){
    56                 f = 0;
    57                break;    
    58             }    
    59         }
    60         if(f) return true;
    61     }
    62     return false;
    63 }
    64 
    65 int main()
    66 {
    67 //    freopen("in.txt", "r", stdin);
    68 
    69     int t;
    70     cin >> t;
    71     while(t--){
    72         cin >> str;
    73         int ans = 0;
    74         p.clear();
    75         for(int i=1; i<=12; i++){
    76             for(int j=1; j<=12; j++){
    77                 if(i*j==12){
    78                     if(calc(i, j)) {
    79                         p.PB(MP(i, j));
    80                         ans++;     
    81                     }
    82                 }
    83             }
    84         }
    85         cout << ans;
    86         for(int i=0; i<ans; i++){
    87             cout << ' ' << p[i].first << 'x' << p[i].second;
    88         }
    89         cout << endl;
    90     }
    91     return 0;
    92 }
    View Code

    Problem B Inna and New Matrix of Candies
    思路:每次找一个最小的然后全部向右移动,计算次数。

    代码如下:

     1 /**************************************************
     2  * Author     : xiaohao Z
     3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
     4  * Last modified : 2014-03-05 23:15
     5  * Filename     : Codeforce_234_2_B.cpp
     6  * Description     : 
     7  * ************************************************/
     8 
     9 #include <iostream>
    10 #include <cstdio>
    11 #include <cstring>
    12 #include <cstdlib>
    13 #include <cmath>
    14 #include <algorithm>
    15 #include <queue>
    16 #include <stack>
    17 #include <vector>
    18 #include <set>
    19 #include <map>
    20 #define MP(a, b) make_pair(a, b)
    21 #define PB(a) push_back(a)
    22 
    23 using namespace std;
    24 typedef long long ll;
    25 typedef pair<int, int> pii;
    26 typedef pair<unsigned int,unsigned int> puu;
    27 typedef pair<int, double> pid;
    28 typedef pair<ll, int> pli;
    29 typedef pair<int, ll> pil;
    30 
    31 const int INF = 0x3f3f3f3f;
    32 const double eps = 1E-6;
    33 const int LEN = 1010;
    34 int Map[LEN][LEN], n, m;
    35 vector<int> p;
    36 
    37 int main()
    38 {
    39 //    freopen("in.txt", "r", stdin);
    40 
    41     string str;
    42     int ans = 1, pos;
    43     while(cin >> n >> m){
    44         ans = 1;
    45         p.clear();
    46         for(int i=0; i<n; i++){
    47             cin >> str;
    48             pos = -1;
    49             for(int j=0; j<m; j++){
    50                 if(str[j] == 'G') pos = j;
    51                 if(pos == -1 && str[j] == 'S') ans = 0;
    52                 if(str[j] == 'S') p.PB(j-pos);
    53             }
    54         }
    55         sort(p.begin(), p.end());
    56     //    for(int i=0; i<p.size(); i++)cout << p[i] << ' ';cout << endl;
    57         int cnt = 0;
    58         for(int i=0; i<p.size(); i++){
    59             if(p[i] == 0) continue;
    60             cnt ++;
    61             for(int j=p.size()-1; j>i; j--){
    62                 p[j] -= p[i];
    63             }
    64         }
    65         if(ans) cout << cnt;
    66         else cout << "-1";
    67         cout << endl;
    68     }
    69     return 0;
    70 }
    View Code

    Problem C Inna and Huge Candy Matrix

    题意:一个矩阵中有糖果,告诉你糖果的位置,然后先顺时针转90度x次,镜像y次,逆时针90度z次问你糖果的位置。

    思路:直接模拟,注意每次旋转交换n和m

    代码如下:

     1 /**************************************************
     2  * Author     : xiaohao Z
     3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
     4  * Last modified : 2014-03-05 23:14
     5  * Filename     : Codeforce_234_2_C.cpp
     6  * Description     : 
     7  * ************************************************/
     8 
     9 #include <iostream>
    10 #include <cstdio>
    11 #include <cstring>
    12 #include <cstdlib>
    13 #include <cmath>
    14 #include <algorithm>
    15 #include <queue>
    16 #include <stack>
    17 #include <vector>
    18 #include <set>
    19 #include <map>
    20 #define MP(a, b) make_pair(a, b)
    21 #define PB(a) push_back(a)
    22 
    23 using namespace std;
    24 typedef long long ll;
    25 typedef pair<int, int> pii;
    26 typedef pair<unsigned int,unsigned int> puu;
    27 typedef pair<int, double> pid;
    28 typedef pair<ll, int> pli;
    29 typedef pair<int, ll> pil;
    30 
    31 const int INF = 0x3f3f3f3f;
    32 const double eps = 1E-6;
    33 int n, m, x, y, z, p, a, b;
    34 
    35 pii ca(pii t, int x){
    36     pii ret;
    37     while(x--){
    38         ret = t;
    39         ret.first = t.second;
    40         ret.second = n - t.first + 1;
    41         t = ret;
    42         swap(n, m);
    43     }
    44     return t;
    45 }
    46 
    47 pii cb(pii t, int x){
    48     pii ret = t;
    49     while(x--){
    50         ret = t;
    51         ret.second = m - t.second + 1;
    52     }
    53     return ret;
    54 }
    55 
    56 pii cc(pii t, int x){
    57     pii ret;
    58     while(x--){
    59         ret = t;
    60         ret.second = t.first;
    61         ret.first = m - t.second + 1;
    62         t = ret;
    63         swap(n, m);
    64     }
    65     return t;
    66 }
    67 
    68 int main()
    69 {
    70 //    freopen("in.txt", "r", stdin);
    71 
    72     pii sw;
    73     int tn, tm;
    74     while(cin >> tn >> tm >> x >> y >> z >> p){
    75         for(int i=0; i<p; i++){
    76             cin >> a >> b;
    77             n = tn, m = tm;
    78             sw = MP(a, b);
    79             sw = ca(sw, x%4);
    80             sw = cb(sw, y%2);
    81             sw = cc(sw, z%4);
    82             cout << sw.first << ' ' << sw.second << endl;
    83         }
    84     }
    85     return 0;
    86 }
    View Code
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    WSL中使用npm install报错
    在npm install时node-gyp出现错误
    Chrome禁用隐藏www和m
    Git始终忽略特定文件的某一行内容
    macOS关闭修改扩展名的提示
    解决安装Anaconda后ZSH中使用的依然是系统自带的Python
    macOS上更顺手的终端
    自用的越狱插件
    Tomcat安装后修改路径方法
    TestStack.White安装详解
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3583723.html
Copyright © 2011-2022 走看看