zoukankan      html  css  js  c++  java
  • Codeforces Round #607 (Div. 2)

    太久没做题就会变得很菜。

    题目链接:https://codeforces.com/contest/1281/


    A:

    白给。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson (curpos<<1)
    15 #define rson (curpos<<1|1)
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 int t;
    21 const int maxn=1010;
    22 char s[maxn];
    23 
    24 int main() {
    25     scanf("%d",&t);
    26     while(t--){
    27         scanf("%s",s+1);
    28         int len=strlen(s+1);
    29         if (s[len]=='o') puts("FILIPINO");
    30         else if (s[len]=='u') puts("JAPANESE");
    31         else puts("KOREAN");
    32     }
    33     return 0;
    34 }
    View Code

    B:

    显然对于每一位,只能跟后面的字符交换。如果只是O(n)扫,遇到第一个s[i]>c[i]的情况才考虑替换的话是错的。应该先把s的副本sort一遍,这样得到的结果是s每个位置交换能得到的最小的字符。当s[i]>s_copy[i],即当前字符有优化空间时就立即考虑替换。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson (minpos<<1)
    15 #define rson (minpos<<1|1)
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 int t;
    21 string a,b;
    22 
    23 int main() {
    24     cin>>t;
    25     while (t--){
    26         cin>>a>>b;
    27         if (a<b){
    28             cout<<a<<'
    ';
    29             continue;
    30         }
    31         string s=a;
    32         sort(s.begin(),s.end());
    33         int flag=0;
    34         for (int i=0;i<(int)a.size();i++){
    35             // current char is not at the best position
    36             if (a[i]>s[i]){
    37                 // it can swap with the back char only
    38                 for (int j=i+1;j<(int)a.size();j++){
    39                     swap(a[i],a[j]);
    40                     if (a<b){
    41                         cout<<a<<'
    ';
    42                         flag=1;
    43                         i=(int)a.size();
    44                         break;
    45                     }
    46                     swap(a[i],a[j]);
    47                 }
    48             }
    49         }
    50         if (!flag) puts("---");
    51     }
    52     return 0;
    53 }
    View Code

    C:

    看似很数学,其实直接模拟就过了。注意当前字符串长度大于等于x时则停止延长字符串即可。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson (curpos<<1)
    15 #define rson (curpos<<1|1)
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int mod = 1e9 + 7;
    21 int t;
    22 
    23 int main() {
    24     ios::sync_with_stdio(false);
    25     cin.tie(0);
    26 
    27     cin >> t;
    28     while (t--) {
    29         int x; string s; cin >> x >> s;
    30         int currLen = (int)s.size();
    31         for (int i = 0; i < x; i++) {
    32             int curr = s[i] - '0';
    33             // length need to grow
    34             if (currLen < x) {
    35                 for (int j = 1; j < curr; j++)
    36                     if ((int)s.size() < x) {
    37                         for (int l = i + 1; l < currLen; l++)
    38                             if ((int)s.size() < x) s += s[l];
    39                     }
    40             }
    41             // calculate current length of string
    42             int d = (currLen - i - 1 + mod) % mod;
    43             currLen = ((i + 1) + (ll)d * curr) % mod;
    44         }
    45         cout << currLen << '
    ';
    46     }
    47     return 0;
    48 }
    View Code

    D:

    分类讨论题。很显然答案只能在[0,4]之间取值。枚举每一行每一列,对于每一行,检查其是否为全A、A在边缘和A在内部的情况,维护答案。列同理。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson (curpos<<1)
    15 #define rson (curpos<<1|1)
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 100;
    21 int t, n, m;
    22 char a[maxn][maxn];
    23 
    24 int main() {
    25     scanf("%d", &t);
    26     while (t--) {
    27         int foundA = 0, foundP = 0, ans = 4;
    28         scanf("%d%d", &n, &m);
    29         for (int i = 1; i <= n; i++) {
    30             scanf("%s", a[i] + 1);
    31             for (int j = 1; j <= m; j++)
    32                 if (a[i][j] == 'A') foundA = 1;
    33                 else foundP = 1;
    34         }
    35         if (!foundA) {
    36             puts("MORTAL");
    37             continue;
    38         }
    39         if (!foundP) {
    40             puts("0");
    41             continue;
    42         }
    43         for (int i = 1; i <= n; i++) {
    44             int maxx = -1, minn = 1000;
    45             for (int j = 1; j <= m; j++) {
    46                 maxx = max(maxx, (int)a[i][j]), minn = min(minn, (int)a[i][j]);
    47                 if (a[i][j] == 'A') {
    48                     int t = 4;
    49                     if (i == 1 || i == n) t--;
    50                     if (j == 1 || j == m) t--;
    51                     ans = min(ans, t);
    52                 }
    53             }
    54             if (maxx == minn && maxx == 'A') {
    55                 if (i == 1 || i == n) ans = min(ans, 1);
    56                 else ans = min(ans, 2);
    57             }
    58         }
    59         for (int j = 1; j <= m; j++) {
    60             int maxx = -1, minn = 1000;
    61             for (int i = 1; i <= n; i++) {
    62                 maxx = max(maxx, (int)a[i][j]), minn = min(minn, (int)a[i][j]);
    63             }
    64             if (maxx == minn && maxx == 'A') {
    65                 if (j == 1 || j == m) ans = min(ans, 1);
    66                 else ans = min(ans, 2);
    67             }
    68         }
    69         printf("%d
    ", ans);
    70     }
    71     return 0;
    72 }
    View Code

    E:

    待补。

  • 相关阅读:
    【DFS】XIII Open Championship of Y.Kupala Grodno SU Grodno, Saturday, April 29, 2017 Problem D. Divisibility Game
    【二分】【三分】【计算几何】XIII Open Championship of Y.Kupala Grodno SU Grodno, Saturday, April 29, 2017 Problem L. Lines and Polygon
    【线段树】XIII Open Championship of Y.Kupala Grodno SU Grodno, Saturday, April 29, 2017 Problem J. Jedi Training
    【贪心】【后缀自动机】XIII Open Championship of Y.Kupala Grodno SU Grodno, Saturday, April 29, 2017 Problem E. Enter the Word
    【转载】随机生成k个范围为1-n的随机数,其中有多少个不同的随机数?
    【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem H. Path or Coloring
    【枚举】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem D. Cutting Potatoes
    【找规律】【递归】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem F. Doubling
    【贪心】Codeforces Round #436 (Div. 2) D. Make a Permutation!
    【计算几何】【圆反演】计蒜客17314 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 G. Finding the Radius for an Inserted Circle
  • 原文地址:https://www.cnblogs.com/JHSeng/p/12045571.html
Copyright © 2011-2022 走看看