• Atcoder ABC161 A~E


    传送门

    A - ABC Swap

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <stack>
     7 #include <queue>
     8 #include <vector>
     9 #include <map>
    10 #include <set>
    11 #include <unordered_set>
    12 #include <unordered_map>
    13 #define ll long long
    14 #define fi first
    15 #define se second
    16 #define pb push_back
    17 #define me memset
    18 const int N = 1e6 + 10;
    19 const int mod = 1e9 + 7;
    20 using namespace std;
    21 typedef pair<int,int> PII;
    22 typedef pair<long,long> PLL;
    23  
    24 int x,y,z;
    25  
    26 int main() {
    27     ios::sync_with_stdio(false);
    28     cin>>y>>z>>x;
    29     printf("%d %d %d\n",x,y,z);
    30  
    31     return 0;
    32 }
    View Code

    B - Popular Vote

     按照题目意思直接写

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <stack>
     7 #include <queue>
     8 #include <vector>
     9 #include <map>
    10 #include <set>
    11 #include <unordered_set>
    12 #include <unordered_map>
    13 #define ll long long
    14 #define fi first
    15 #define se second
    16 #define pb push_back
    17 #define me memset
    18 const int N = 1e6 + 10;
    19 const int mod = 1e9 + 7;
    20 using namespace std;
    21 typedef pair<int,int> PII;
    22 typedef pair<long,long> PLL;
    23  
    24 int n;
    25 double m;
    26 double a[N];
    27 double sum=0;
    28 int main() {
    29     ios::sync_with_stdio(false);
    30     cin>>n>>m;
    31      for(int i=0;i<n;++i){
    32          cin>>a[i];
    33          sum+=a[i];
    34      }
    35      sort(a,a+n);
    36  
    37      double check=sum/(4*m);
    38      int cnt=0;
    39      for(int i=n-1;i>=0;--i){
    40          if(a[i]>=check) cnt++;
    41          if(cnt==m){
    42              printf("Yes\n");
    43              return 0;
    44          }
    45      }
    46      printf("No\n");
    47  
    48  
    49     return 0;
    50 }
    View Code

    C - Replacing Integer

    题意:给你两个整数x和K,每次用abs(x-K)替换x,求替换后x的最小值

    题解:如果x%k==0,那么最小值就是0,否则取x除K的余数和K减其余数的最小值即可

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <stack>
     7 #include <queue>
     8 #include <vector>
     9 #include <map>
    10 #include <set>
    11 #include <unordered_set>
    12 #include <unordered_map>
    13 #define ll long long
    14 #define fi first
    15 #define se second
    16 #define pb push_back
    17 #define me memset
    18 const int N = 1e6 + 10;
    19 const int mod = 1e9 + 7;
    20 using namespace std;
    21 typedef pair<int,int> PII;
    22 typedef pair<long,long> PLL;
    23 
    24 ll n,k;
    25 
    26 int main() {
    27     ios::sync_with_stdio(false);
    28     cin>>n>>k;
    29     if(n%k==0){
    30         printf("0\n");
    31     }
    32     else{
    33         printf("%lld\n",min(n%k,k-(n%k)));
    34     }
    35 
    36     return 0;
    37 }
    View Code

    D - Lunlun Number

    题意:对于某个数X,如果它的每一位数的差的绝对值都<=1,那么这个数就是一个“lunlun num”,现在求第k小的“lunlun num”是多少

    题解:用一个单调队列来存"lunlun num",每次取一个数,将它当前个位的数 +1,+0,-1,添加到它新的个位即可,要注意特判个位是0和9的时候,分别不能放-1和+1;

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <stack>
     7 #include <queue>
     8 #include <vector>
     9 #include <map>
    10 #include <set>
    11 #include <unordered_set>
    12 #include <unordered_map>
    13 #define ll long long
    14 #define fi first
    15 #define se second
    16 #define pb push_back
    17 #define me memset
    18 const int N = 1e6 + 10;
    19 const int mod = 1e9 + 7;
    20 using namespace std;
    21 typedef pair<int,int> PII;
    22 typedef pair<long,long> PLL;
    23  
    24 int k;
    25 ll q[N],hh=1,tt=0;
    26  
    27 int main() {
    28     ios::sync_with_stdio(false);
    29     cin>>k;
    30     if(k<=12){
    31         printf("%d\n",k);
    32         return 0;
    33     }
    34  
    35     for(int i=1;i<=9;++i) q[++tt]=i;
    36  
    37     int cnt=0;
    38     ll ans;
    39     while(cnt!=k){
    40         ll now=q[hh];
    41         hh++;
    42         ll res=now%10;
    43  
    44         if(res!=0) q[++tt]=now*10+res-1,cnt++;
    45         if(cnt==k-10+1){
    46            ans=q[tt];
    47            break;
    48         }
    49         q[++tt]=now*10+res,cnt++;
    50         if(cnt==k-10+1){
    51             ans=q[tt];
    52             break;
    53         }
    54         if(res!=9) q[++tt]=now*10+res+1,cnt++;
    55         if(cnt==k-10+1){
    56             ans=q[tt];
    57             break;
    58         }
    59     }
    60    printf("%lld\n",ans);
    61  
    62  
    63     return 0;
    64 }
    View Code

    E - Yutori

    题意:你想在N天中工作k天,但你每工作一天就要休息c天,给你一个字符串s,只有s[i]=‘o'的时候,你才能在第i天工作,所以在哪天工作,你有多种选择,求你在这么多天中有哪几天是必须要工作的

    题解:(贪心)首先从头正的遍历一边,如果能工作那么就L[x]++,这样一定能确定我们所选的工作日都是最早的,然后再反的遍历一边,如果能工作就R[x]++,得到的所有工作日一定是最晚的,那对于任意的i,如果有L[i]==R[i],这一天就一定会选.

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <stack>
     7 #include <queue>
     8 #include <vector>
     9 #include <map>
    10 #include <set>
    11 #include <unordered_set>
    12 #include <unordered_map>
    13 #define ll long long
    14 #define fi first
    15 #define se second
    16 #define pb push_back
    17 #define me memset
    18 const int N = 1e6 + 10;
    19 const int mod = 1e9 + 7;
    20 using namespace std;
    21 typedef pair<int,int> PII;
    22 typedef pair<long,long> PLL;
    23  
    24 int n,k,c;
    25 string s;
    26 vector<int> L,R;
    27  
    28 int main() {
    29     ios::sync_with_stdio(false);
    30     cin>>n>>k>>c>>s;
    31  
    32     for(int i=0;i<s.size();++i){
    33         if(s[i]=='o') L.pb(i),i+=c;
    34         if(L.size()==k) break;
    35     }
    36     for(int i=s.size()-1;i>=0;--i){
    37         if(s[i]=='o') R.pb(i),i-=c;
    38         if(R.size()==k) break;
    39     }
    40  
    41     for(int i=0;i<k;++i){
    42         if(L[i]==R[k-i-1])
    43             printf("%d\n",L[i]+1);
    44     }
    45  
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    哪个项目管理工具好用到哭?JIRA VS 华为软件开发云
    华为软件开发云CloudIDE功能简测
    移动APP云测试平台测评分析
    华为软件开发云对比Jenkins-JavaWeb项目持续部署方式
    微服务究竟该如何理解
    如何将Android Studio与华为软件开发云代码仓库无缝对接(二)
    如何将Android Studio与华为软件开发云代码仓库无缝对接(一)
    微服务,真的适合你么?
    如何更换git托管
    Redmine迁移至华为软件开发云-项目管理
  • 原文地址:https://www.cnblogs.com/lr599909928/p/12643272.html
Copyright © 2020-2023  润新知