zoukankan      html  css  js  c++  java
  • 牛客练习赛16

    A.典序最大的子序列

    倒着贪心

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 char s[111111];
     4  
     5 int main(){
     6     string ans = "";
     7     scanf("%s", s + 1);
     8     int len = strlen(s + 1);
     9     ans += s[len];
    10     for(int i = len - 1; i >= 1; i--){
    11         if(s[i] >= ans[ans.length()-1]) ans += s[i];
    12     }
    13     reverse(ans.begin(), ans.end());
    14     cout << ans << endl;
    15     return 0;
    16 }
    Aguin

    B.亮的树

    减个等差

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 1e5;
     4 int a[maxn];
     5 map<int, int> cnt;
     6 map<int, int> :: iterator it;
     7  
     8 int main(){
     9     int n;
    10     scanf("%d", &n);
    11     for(int i = 1; i <= n; ++i) scanf("%d", a + i);
    12     for(int i = 1; i <= n / 2; ++i){
    13         a[i] -= i;
    14         a[n-i+1] -= i;
    15         cnt[a[i]]++;
    16         cnt[a[n-i+1]]++;
    17     }
    18     if(n % 2) a[n/2+1] -= n/2+1, cnt[a[n/2+1]]++;
    19     int ans = n;
    20     for(it = cnt.begin(); it != cnt.end(); it++){
    21         ans = min(ans, n - (*it).second);
    22     }
    23     cout << ans << endl;
    24     return 0;
    25 }
    Aguin

    C.意点

    数连通块

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int fa[111];
     4 int Find(int x){
     5     return fa[x] == x ? x : fa[x] = Find(fa[x]);
     6 }
     7 void Union(int x, int y){
     8     x = Find(x), y = Find(y);
     9     fa[x] = y;
    10 }
    11 int xx[111], yy[111];
    12 int main(){
    13     int n, ans = -1;
    14     scanf("%d", &n);
    15     for(int i = 1; i <= n; ++i){
    16         fa[i] = i;
    17         scanf("%d %d", xx + i, yy + i);
    18         for(int j = 1; j < i; ++j)
    19             if(xx[i] == xx[j] || yy[i] == yy[j]) Union(i, j);
    20     }
    21     for(int i = 1; i <= n; ++i){
    22         if(fa[i] == i) ans++;
    23     }
    24     printf("%d
    ", ans);
    25     return 0;
    26 }
    Aguin

    D.k进制数

    模k-1不变

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int maxn = 1e5 + 10;
     5 LL a[maxn], sum[maxn];
     6 map<LL, LL> cnt;
     7  
     8 int main(){
     9     LL k, b, n, ans = 0, t = 0, z = 0;
    10     scanf("%lld %lld %lld", &k, &b, &n);
    11     for(int i = 1; i <= n; ++i){
    12         scanf("%lld", a + i);
    13         sum[i] = (sum[i-1] + a[i]) % (k - 1);
    14         if(a[i] == 0) t++, z += t;
    15         else t = 0;
    16     }
    17     if(b == 0) ans = z;
    18     else {
    19         cnt[0]++;
    20         for(int i = 1; i <= n; ++i)
    21             ans += cnt[(sum[i]-b+k-1)%(k-1)], cnt[sum[i]]++;
    22         if(b == k - 1) ans -= z;
    23     }
    24     printf("%lld
    ", ans);
    25     return 0;
    26 }
    Aguin

    E.

    找变化点

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int maxn = 1e5 + 10;
     5 LL a[maxn];
     6 set<int> pos, v;
     7 set<int> :: reverse_iterator it;
     8  
     9 int main(){
    10     int n;
    11     scanf("%d", &n);
    12     for(int i = 1; i <= n; ++i){
    13         scanf("%d", a + i);
    14         v.insert(a[i]);
    15         int tmp = a[i];
    16         vector<int> cl;
    17         for(it = pos.rbegin(); it != pos.rend(); it++){
    18             if((a[*it] | tmp) != tmp) tmp |= a[*it], v.insert(tmp);
    19             else cl.push_back(*it);
    20         }
    21         for(int j = 0; j < cl.size(); j++) pos.erase(cl[j]);
    22         pos.insert(i);
    23     }
    24     printf("%d
    ", v.size());
    25     return 0;
    26 }
    Aguin

    F.

    随便加加

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int maxn = 1e5 + 10;
     5 LL a[maxn];
     6  
     7 int main(){
     8     int n;
     9     LL d, ans = 0;
    10     scanf("%d %lld", &n, &d);
    11     for(int i = 1; i <= n; ++i){
    12         scanf("%lld", a + i);
    13         int j = lower_bound(a + 1, a + 1 + i, a[i] - d) - a;
    14         ans += (i - j) * (LL)(i - j - 1) / 2;
    15     }
    16     cout << ans << endl;
    17     return 0;
    18 }
    Aguin
  • 相关阅读:
    RabbitMQ系列教程之七:RabbitMQ的 C# 客户端 API 的简介
    RabbitMQ系列教程之六:远程过程调用(RPC)
    git无法提交,存在未提交的修改,在重新合并前或者撤销更改
    安装mysql提示3306端口已经被占用解决方案
    区块链学习一基本知识
    超级账本 --- ReadWriteSet的逻辑结构
    解决windows10 里vs2015 附件进程调试提示“此任务要求应用程序有提升的权限”
    Fabric V1 交易的生命周期
    sql 取首次投资的人
    Win10年度更新开发必备:VS2015 Update 3正式版下载汇总
  • 原文地址:https://www.cnblogs.com/Aguin/p/8965788.html
Copyright © 2011-2022 走看看