• Codeforces Round #620 (Div. 2)ABC


    A. Two Rabbits

    两点之间的距离每次减少 a+b,初始时距离为 y-x
    如果两个人恰好遇到,那么 (y-x)%(a+b)==0
    时间为 (y-x)/(a+b)

    #include <bits/stdc++.h>
    using namespace std;
    const double pi = acos(-1.0);
    #define x first
    #define y second
    #define LL long long 
    #define int LL
    #define pb push_back
    #define all(v) (v).begin(),(v).end()
    #define PII pair<int,int>
    #define ll_INF 0x7f7f7f7f7f7f7f7f
    #define INF 0x3f3f3f3f
    #define debug(x) cerr << #x << ": " << x << endl
    #define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
    LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
    LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
    LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
    int _;
    int n;
    int gcd(int a,int b)
    {
    	return b?gcd(b,a%b):a;
    }
    void solve()
    {
    	int x,y,a,b;
    	cin>>x>>y>>a>>b;
    	if((y-x)%(a+b))cout<<-1<<endl;
    	else cout<<(y-x)/(a+b)<<endl;
    }
    signed main()
    {
        io;
      	cin>>_; 
     	while(_--)
        solve();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    B. Longest Palindrome

    思路:暴力枚举,首先先找出自身回文得放在中间,只能有一个
    然后存储互相回文得字符出输出即可

    #include <bits/stdc++.h>
    using namespace std;
    const double pi = acos(-1.0);
    #define x first
    #define y second
    #define LL long long 
    #define int LL
    #define pb push_back
    #define all(v) (v).begin(),(v).end()
    #define PII pair<int,int>
    #define ll_INF 0x7f7f7f7f7f7f7f7f
    #define INF 0x3f3f3f3f
    #define debug(x) cerr << #x << ": " << x << endl
    #define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
    LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
    LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
    LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
    int _;
    int n,m;
    const int N=110;
    vector<string>v;
    int gcd(int a,int b)
    {
    	return b?gcd(b,a%b):a;
    }
    bool check(string s)
    {
    	string t=s;
    	reverse(all(t));
    	return s==t;
    }
    void solve()
    {
    	cin>>n>>m;
    	string s;
    	map<string,bool>mp;
    	vector<string>v1,v2;
    	string mid="";
    	for(int i=0;i<n;i++)
    	{
    		cin>>s;
    		v.pb(s);
    	}
    	for(int i=0;i<n;i++)
    	{
    		if(check(v[i]))
    		{
    			mid=v[i];
    			continue;
    		}
    		for(int j=0;j<n;j++)
    		{
    			if(j==i)continue;
    			string t=v[i]+v[j];
    			if(check(t)&&mp[v[i]]==false&&mp[v[j]]==false)
    			{
    				v1.pb(v[i]);
    				v2.pb(v[j]);
    				mp[v[i]]=mp[v[j]]=true;
    			}
    		}
    	}
    	int len=v1.size()+v2.size();
    	if(mid!="")len++;
    	cout<<len*m<<endl;
    	for(int i=0;i<v1.size();i++)cout<<v1[i];
    	if(mid!="")cout<<mid;
    	for(int i=v2.size()-1;i>=0;i--)cout<<v2[i];
    	cout<<endl;
    }
    signed main()
    {
        io;
      //	cin>>_; 
     //	while(_--)
        solve();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78

    C. Air Conditioner

    思路:贪心,维护区间

    #include <bits/stdc++.h>
    using namespace std;
    const double pi = acos(-1.0);
    #define x first
    #define y second
    #define LL long long 
    #define int LL
    #define pb push_back
    #define all(v) (v).begin(),(v).end()
    #define PII pair<int,int>
    #define ll_INF 0x7f7f7f7f7f7f7f7f
    #define INF 0x3f3f3f3f
    #define debug(x) cerr << #x << ": " << x << endl
    #define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
    LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
    LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
    LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
    int _;
    int n,m;
    const int N=110;
    struct node
    {
    	int t,l,r;
    }c[N];
    void solve()
    {
    	cin>>n>>m;
    	for(int i=1;i<=n;i++)cin>>c[i].t>>c[i].l>>c[i].r;
    	bool f=false;
    	int l=m,r=m;
    	for(int i=1;i<=n;i++)
    	{
    		int d=c[i].t-c[i-1].t;
    		l-=d,r+=d;
    		if(l>c[i].r||r<c[i].l)
    		{
    			f=true;
    			break;
    		}
    		l=max(l,c[i].l),r=min(r,c[i].r);
    	}
    	if(f)cout<<"NO"<<endl;
    	else cout<<"YES"<<endl;
    }
    signed main()
    {
        io;
      	cin>>_; 
     	while(_--)
        solve();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
  • 相关阅读:
    Arcgis如何制作专题地图中漂亮的饼图
    Python_玩转多线程_一蓑烟雨任平生
    使用Spring Boot双数据源和PageHelper实现无缝分页查询
    异常(Exception)
    电容笔和触控笔有哪些区别?超高性价比电容笔排行
    快速上手Linux核心命令(七):Linux系统信息相关命令
    Android 10.0 framework层实现app默认全屏显示
    ubuntu 下安装C/C++ 开发环境
    [SLAM] IMU预积分推导
    socket编程
  • 原文地址:https://blog.csdn.net/qq_52765554/article/details/125416782