zoukankan      html  css  js  c++  java
  • AtCoder Regular Contest 069

    1. C - Scc Puzzle

    计算scc的个数,先判断s个数需要多少个cc,多的cc,每四个可以组成一个scc。注意数据范围,使用long long.

     1 #include<bits/stdc++.h>
     2 #define pb push_back
     3 #define FOR(i, n) for (int i = 0; i < (int)n; ++i)
     4 #define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
     5 typedef long long ll;
     6 using namespace std;
     7 typedef pair<int, int> pii;
     8 const int maxn = 1e3 + 10;
     9 void solve() {
    10     ll x, y;
    11     while(cin >> x >> y) {
    12         ll res = 0;
    13         if(y >= 2 * x) {
    14             res = x + (y - 2 * x) / 4;
    15         } else {
    16             res = y / 2;
    17         }
    18         cout << res << endl;
    19     }
    20 }
    21 int main() {
    22     //freopen("test.in", "r", stdin);
    23     //freopen("test.out", "w", stdout);
    24     ios::sync_with_stdio(0);
    25     cin.tie(0); cout.tie(0);
    26     solve();
    27     return 0;
    28 }
    View Code

    2. D - Menagerie

    读完题目,感觉是无从下手,3 <= n <= 1e5,暴力判断每一个字符串,肯定会tle,然后就要想其他方法了。

    然后突然想到:固定前2个数,然后其他的位置可以推导出来,最后判断第一个和最后一个位置是否合法就可以了。

    我写的又长又臭,哎,先这样吧,慢慢改进。

      1 #include<bits/stdc++.h>
      2 #define pb push_back
      3 #define FOR(i, n) for (int i = 0; i < (int)n; ++i)
      4 #define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
      5 typedef long long ll;
      6 using namespace std;
      7 typedef pair<int, int> pii;
      8 const int maxn = 1e3 + 10;
      9  int n;
     10  vector<bool> res;
     11 bool work(const string &s) {
     12     for (int i = 1; i < n - 1; i++) {
     13         if(s[i] == 'o') {
     14             if(res[i]) {
     15                 res[i + 1] = !res[i - 1];
     16             } else {
     17                 res[i + 1] = res[i - 1];
     18             }
     19         } else {
     20             if(res[i]) {
     21                 res[i + 1] = res[i - 1];
     22             } else {
     23                 res[i + 1] = !res[i - 1];
     24             }
     25         }
     26     }
     27     bool f1, f2;
     28     f1 = f2 = 0;
     29     if(s[n - 1] == 'o') {
     30         if(res[n - 1]) {
     31             f1 =  res[n - 2] != res[0];
     32         } else {
     33             f1 =  res[n - 2] == res[0];
     34         }
     35     } else {
     36         if(res[n - 1]) {
     37             f1 =  res[n - 2] == res[0];
     38         } else {
     39             f1 =  res[n - 2] != res[0];
     40         }
     41     }
     42  
     43     if(s[0] == 'o') {
     44         if(res[0]) {
     45             f2 =  res[n - 1] != res[1];
     46         } else {
     47             f2 =  res[n - 1] == res[1];
     48         }
     49     } else {
     50         if(res[0]) {
     51             f2 =  res[n - 1] == res[1];
     52         } else {
     53             f2 =  res[n - 1] != res[1];
     54         }
     55     }
     56     return f1 && f2;
     57 }
     58 void pr() {
     59     for (int i = 0; i < n; i++) {
     60         if(res[i]) cout << 'W';
     61         else cout << 'S';
     62     }
     63     cout << endl;
     64 }
     65 void solve() {
     66     string s;
     67     while(cin >> n) {
     68         cin >> s;
     69         res.clear();
     70         res.resize(n);
     71         res[0] = res[1] = 0;
     72         bool f = work(s);
     73         if(f) {
     74             pr();
     75             continue;
     76         }
     77         res[0] = res[1] = 1;
     78         f = work(s);
     79         if(f) {
     80             pr();
     81             continue;
     82         }
     83         res[0] = 1; res[1] = 0;
     84         f = work(s);
     85         if(f) {
     86             pr();
     87             continue;
     88         }
     89         res[0] = 0; res[1] = 1;
     90         f = work(s);
     91         if(f) {
     92             pr();
     93             continue;
     94         }
     95         cout << -1 << endl;
     96     }
     97 }
     98 int main() {
     99   //  freopen("test.in", "r", stdin);
    100     //freopen("test.out", "w", stdout);
    101     ios::sync_with_stdio(0);
    102     cin.tie(0); cout.tie(0);
    103     solve();
    104     return 0;
    105 }
    View Code

    3. E - Frequency

    1<=n<=1e5,1<=a<=1e9,数据范围很大,不可能一个一个的模拟。注意结果可能需要long long来保存。

    考虑最大的数,然后递减到次大的数,然后每次维护一下这些数的index的最小值,依次统计,最后输出。

    使用set来维护数的顺序,同时记录index.

     1 #include<bits/stdc++.h>
     2 #define pb push_back
     3 #define FOR(i, n) for (int i = 0; i < (int)n; ++i)
     4 #define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
     5 typedef long long ll;
     6 using namespace std;
     7 typedef pair<int, int> pii;
     8 const int maxn = 1e5 + 10;
     9 int a[maxn];
    10 set<int> se;
    11 map<int, vector<int>> tag;
    12 map<int, int> sz;
    13 ll res[maxn];
    14 int n;
    15 void solve() {
    16     cin >> n;
    17     for (int i = 0; i < n; i++) {
    18         cin >> a[i];
    19         se.insert(a[i]);
    20         sz[a[i] ]++;
    21         tag[a[i] ].pb(i + 1);
    22     }
    23     while(se.size() > 1) {
    24         int t = *se.rbegin();
    25         se.erase(t);
    26         int nt = *se.rbegin();
    27         int mi = tag[t][0];
    28         for (int x : tag[t]) {
    29             mi = min(mi, x);
    30         }
    31         tag[nt].pb(mi);
    32         res[mi] += 1ll * (t - nt) * sz[t];
    33         sz[nt] += sz[t];
    34     }
    35     int t = *se.begin();
    36     int mi = tag[t][0];
    37     for (int x : tag[t]) mi = min(mi, x);
    38     res[mi] += 1ll * t * sz[t];
    39     for (int i = 1; i <= n; i++)
    40         cout << res[i] << endl;
    41 }
    42 int main() {
    43    // freopen("test.in", "r", stdin);
    44     //freopen("test.out", "w", stdout);
    45     ios::sync_with_stdio(0);
    46     cin.tie(0); cout.tie(0);
    47     solve();
    48     return 0;
    49 }
    View Code

    4。 F - Flags

    题目很简短,不知道怎么做。官方题解只有日语的,没有进一步用翻译去看,有时间,搞一下。

  • 相关阅读:
    [Matlab.Matrix] 作为判断条件
    [Matlab.GUI] 学习小结
    [Modelsim] 初识
    [Matlab] isnan
    [Matlab] round
    [VS2012] 无法查找或打开 PDB 文件
    [Matlab.GUI]初识
    表格特效代码全集中
    JAVASCRIPT基础
    第4天:调用样式表
  • 原文地址:https://www.cnblogs.com/y119777/p/6415762.html
Copyright © 2011-2022 走看看