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

    小牧又偷懒了,最近两天发生了很多事,小牧彻底变单身,不回头,一切向ICPC看起,生活还要继续,即使全世界都不在意你,你也要自强不息,当你变得优秀的时候这些都是你的故事。生活还要继续,我还要我的金牌而努力。

    今天呢补一下之前的div2

    通天路

    A题

    题意:k次询问,每次给你一个数n,然后给你n个数表示木板长度(宽度默认为1),求这些木板所能够拼凑的最大正方形,输出边长

    思路:将n个数排序,从大到小,记录木棍的根数,当根数大于当前位置木棍长度时,最大正方形的边长是根数减一。

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <string>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 typedef long long ll;
     9 int main()
    10 {
    11     int k;
    12     cin >> k;
    13     while(k--)
    14     {
    15         int n;
    16         cin >> n;
    17         int a[1010];
    18         for(int i=1;i<=n;i++)
    19         {
    20             cin >> a[i];
    21         }
    22         sort(a+1,a+n+1);
    23         if(a[n]==a[1])
    24         {
    25             cout << a[n]<<endl;
    26             continue;
    27         }
    28         int num =0,i=n;
    29         while(a[i]>num&&i>0)
    30         {
    31             i--;
    32             num++;
    33         }
    34         cout << num <<endl;
    35     }
    36     return 0;
    37 }
    View Code

    B1题

    题意:给你两个长度为n的字符串,只能交换一次(且只能是从这串到另一个串交换),如果经过转换可以得到两个一样的字符串,则输出YES否则输出NO

    思路:暴力枚举两个串,找到两个串对应不一样的点,记录点数,(且一定要是是s[i]!=t[i]&&s[j]==s[i]&&t[j]==t[i])

     1 #include <iostream>
     2 #include <cstring>
     3 #include <string>
     4 #include <cstdio>
     5 #include <algorithm>
     6 #include <map>
     7 
     8 using namespace std;
     9 typedef long long ll;
    10 map<char,int>mp,q;
    11 int main()
    12 {
    13     int k;
    14     cin >> k;
    15     while(k--)
    16     {
    17         int n;
    18         cin >> n;
    19         string s,t;
    20         cin >> s;
    21         cin >> t;
    22         char a=0,b=0;
    23         int num =0;
    24         int flag = 0;
    25         for(int i=0;i<n;i++)
    26         {
    27            if(s[i]!=t[i])
    28            {
    29                num++;
    30                if(a==0&&b==0)
    31                {
    32                    a=s[i];
    33                    b=t[i];
    34                    continue;
    35                }
    36                else{
    37                 if(a==s[i]&&b==t[i])flag=1;
    38                 //cout <<a <<s[i]<<b<<t[i]<<endl;
    39                }
    40            }
    41         }
    42         if(num==2&&flag==1)
    43         {
    44             cout<<"Yes"<<endl;
    45         }
    46         else{
    47             cout <<"No"<<endl;
    48         }
    49     }
    50     return 0;
    51 }
    View Code

    B2题

    题意:给你两个长度为n的两个串,最多可以经过2n次交换(不能相同串交换),如果经过变换可以得两个相同的字符串,则输出yes和交换的次序对,否则输出NO

    思路:遍历字符串,每个位置的s,t两串有三种情况:1.两个相等,则直接跳过;2.两不相等,但可以在(当前位置往后)找到与s[i]相等的s[k],则交换s[k]和t[i],并将选择对存起来;

    3.两不相等,但可以在(当前位置往后)找到与s[i]相等的t[k],则交换s[i]和t[i],在交换s[i]和t[k],并将选择对存起来;

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cmath>
     5 #include <cstring>
     6 #include <string>
     7 #include <map>
     8 #include <queue>
     9 using namespace std;
    10 typedef long long ll;
    11 map<char,int>mp;
    12 vector<pair<int,int>>v;
    13 
    14 int main()
    15 {
    16     int k;
    17     cin >> k;
    18     while(k--)
    19     {
    20         v.clear();
    21         int p;
    22         cin >> p;
    23         string s,ss;
    24         cin >> s >> ss;
    25         for(int i=0;i<p;i++)
    26         {
    27             for(int k=i+1;k<p;k++)
    28             {
    29                 if(s[i]==ss[i])break;
    30                 if(s[k]==s[i])
    31                 {
    32                     swap(ss[i],s[k]);
    33                     v.push_back({k,i});
    34                 }
    35                 else if(ss[k]==s[i])
    36                 {
    37                     swap(ss[i],ss[k]);
    38                     v.push_back({i,i});
    39                     v.push_back({i,k});
    40                 }
    41             }
    42         }
    43         if(ss==s){
    44             //cout << s<<endl;
    45             //cout << ss <<endl;
    46             cout <<"Yes"<<endl;
    47             cout <<v.size()<<endl;
    48             for(auto vp: v)
    49             {
    50                 cout << vp.first+1<<" "<<vp.second+1<<endl;
    51             }
    52         }
    53         else{
    54             cout <<"No"<<endl;
    55         }
    56     }
    57 }
    View Code

    C题

    题意:一个长度为n的彩带(含有n个小正方形),对于任意n%|i-j|==0的话,第i个正方形和第J个正方形颜色相同,要求输出最多的颜色数量

    思路:就是n约数嘛,分三种情况:1.当n是素数时,最多就有n种颜色;2.当n的质因数只有一个时,就是n = pow(x,y)[x是n的唯一质因数,y是任意次方],这个时候颜色最多有n的唯一质因数个3.就是n不止一个质因数,那就只能是一种颜色,因为这些质因数就是颜色相同的不同跨度,但他们有一个共同的倍数,都会过一个点【1,n】因此颜色都会是一样的。

     1 #include <iostream>
     2 #include <cstring>
     3 #include <string>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <cstdio>
     7 #include <vector>
     8 
     9 using namespace std;
    10 typedef long long ll;
    11 
    12 int main()
    13 {
    14     ll n;
    15     cin >> n;
    16     for(int i=2;i<=sqrt(n);i++)
    17     {
    18         if(n%i==0)
    19         {
    20             while(n%i==0)
    21             {
    22                 n/=i;
    23             }
    24             if(n>1)
    25             {
    26                 cout <<1<<endl;
    27                 return 0;
    28             }
    29             else{
    30                 cout << i<<endl;
    31                 return 0;
    32             }
    33         }
    34     }
    35     cout << n << endl;
    36     return 0;
    37 }
    View Code

    再多的不舍,你也不会回来,也许你永远都不会看我的博客,你也许从未在意我的博客,也许那句话是对的,你认真你就输了,我来来回回说放下,搞了好多次,但我一次次回头,一次次回来找你,你的冷淡,你的不理不睬,你没有错,错只是我走出来的太慢了,今天之后,我不会再去找你,再见了,我的幻想。

    你的脸上风淡云轻,谁也不知道你的牙咬得有多紧。你走路带着风,谁也不知道你膝盖上仍有曾摔过的伤的淤青。你笑得没心没肺,没人知道你哭起来只能无声落泪。要让人觉得毫不费力,只能背后极其努力。我们没有改变不了的未来,只有不想改变的过去。
  • 相关阅读:
    An unhandled exception occurred while processing the request.
    PIP升级或更新、PIP 升级 或 更新 失败
    SQL求两个时间差
    EF Core DBFirst 和Code First小结
    Core + Vue 后台管理基础框架9——统一日志
    .Net Core 访问 appsettings.json
    IdentityServer4 (5) 混合模式(Hybrid)
    C# async/await、WhenAll、ContinueWith 实战应用(异步做早餐)
    .NET Core Web APi FormData多文件上传,IFormFile强类型文件灵活绑定
    Unity3D天气系统插件UniStorm插件使用说明
  • 原文地址:https://www.cnblogs.com/wangzhe52xia/p/buzaihuitou.html
Copyright © 2011-2022 走看看