Codeforces Round #692 (Div. 2, based on Technocup 2021 Elimination Round 3) ABC

Problem - A - Codeforces

题目大意:如果字符串末尾的字符数‘)’严格大于剩余字符数,则消息是错误的。

【字符串s末尾的)要严格大于剩下的则为Yes,否则为No 】

input

5
2
))
12
gl))hf))))))
9
gege)))))
14
)aa))b))))))))
1
)

output

Yes
No
Yes
Yes
Yes
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n;
        string s; cin>>s;
        int sum=0;
        for(int i=s.length()-1;i>=0;i--)
        {
            if(s[i]==')')sum++;
            else break;
        }
        //cout<<sum<<endl;
        if(sum>n-sum) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Problem - B - Codeforces

题目大意:如果一个正整数可以被它的每个非零位整除,我们称它为公平的。例如,102是公平的(因为它可以被1和2整除),但第282不是,因为它不能被8整除。给定一个正整数n,找出最小整数x,使n≤x和x是公平的。

一个正整数可以被它的每个非零位整除(1和0直接排除,用暴力循环做)

input

4
1
282
1234567890
1000000000000000000

output

1
288
1234568040
1000000000000000000

注意事项。
部分测试用例说明:
在第一个测试案例中,1号本身是公平的。
在第二个测试用例中,编号288是公平的(它可以被2和8整除)。[282,287]中没有一个数字是公平的,因为,例如,它们都不能被8整除。 

/*知识点
  函数原型:
    string to_string (int val);
    string to_string (long val);
    string to_string (long long val);
    string to_string (unsigned val);
    string to_string (unsigned long val);
    string to_string (unsigned long long val);
    string to_string (float val);
    string to_string (double val);
    string to_string (long double val);
  功能:
    将数值转化为字符串。返回对应的字符串
eg:
#include<iostream>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin>>t;
    while(t--)
    {
        long long int n; cin>>n;
        string s=to_string(n);
        cout<<s<<endl;
    }
    return 0;
}*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin>>t;
    while(t--)
    {
        long long int n; cin>>n;
        while(1)
        {
            int flag=0;
            string s=to_string(n);
            for(int i=0;i<s.length();i++)
            {
                if(s[i]=='0'||s[i]=='1') continue;
                else if(n%(s[i]-'0')!=0) { flag=1; break; }
            }
            if(flag==1) n++;
            else break;
        }
        cout<<n<<endl;
    }
    return 0;
}

Problem - C - Codeforces

题目大意:一个n×n的棋盘。黑板的行号和列号从1到n。单元格(x,y)位于列号x和行号y的交点上。一个棋子,可以在一个回合中垂直或水平移动任意数量的单元格。(即不存在共享一行或一列的一对车。)在一个回合中,你可以将一辆车垂直或水平移动任意数量的单元格。另外,它在移动后不应该被任何其他车攻击。把所有的车挂在主对角线上所需的最少移动次数是多少?(保证在最初的位置不会有两个菜鸟互相攻击。)【将所有的点(不在同一行同一列)都跳到对角线上去,求最小的步数 】

input

4
3 1
2 3
3 2
2 1
1 2
5 3
2 3
3 1
1 2
5 4
4 5
5 1
2 2
3 3

output

1
3
4
2
/*
知识点
acwing朴素并查集:
int p[N]; //存储每个点的祖宗节点
int find(int x)//返回x的祖宗节点
{
    if(p[x]!=x) p[x]=find(p[x]);
    return p[x];
}
for(int i=1;i<=n;i++) p[i]=i;//初始化,假定节点编号是1~n
p[find(a)] = find(b);//合并a和b所在的两个集合
*/
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
using namespace std;
const int maxn=1e6+10;
using namespace std;
int p[maxn];
int find(int x)
{
    if(x!=p[x]) p[x]=find(p[x]);
    return p[x];
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin>>t;
    while(t--)
    {
        int n,m; cin>>n>>m;
        for(int i=1;i<=n;i++) p[i]=i;//并查集模板初始化条件
        int cnt=0,ans=0;
        while(m--)
        {
            int x,y; cin>>x>>y;
            if(x==y) continue;//当x和y相等时,已经在对角线上了,直接跳过不用合并
            if(find(x)!=find(y)) p[find(x)]=find(y);//当两者的祖先都不一样的时候,合并x和y的两个集合
            else cnt++;//当形成了环的时候就直接加一个
            ans++;//ans==m就是点数
        }
        cout<<ans+cnt<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vijurria

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值