Codeforces Round #620 (Div. 2)

心态崩了丫…一个小时A出ABC,然后就WA了一小时的D…

A. Two Rabbits

难的出这么简单,真香!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e6+10;
 
vector<pair<int,string> >v,ans;
 
int main()
{
    int t;  cin>>t;
    while(t--)
    {
        int x,y,a,b;
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)
            cout<<(y-x)/(a+b)<<endl;
        else
            cout<<"-1"<<endl;
    }
    return 0;
}

B. Longest Palindrome

B其实正常,直接用map记录,然后不断的reverse字符串,详细的直接看代码就行

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
int main()
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	map<string, int> freq;
	string a;   string b;
	for(int i = 0; i < n; i++)
    {
		string q;   cin >> q;
		string rq = q;
		reverse(rq.begin(), rq.end());
		if(freq[rq] >= 1)
		{
			freq[rq]--;
			a += rq;
			b += rq;
		} else 
		{
			freq[q]++;
		}
	}
	for(auto r : freq)
	{
		string q = r.first;
		string rq = q;
		reverse(rq.begin(), rq.end());
		if(r.second >= 1 && q == rq)
		{
			a += q;
			break;
		}
	}
	reverse(b.begin(), b.end());
	a += b;
	cout << a.size() << '\n';
	cout << a << '\n';
}

C. Air Conditioner

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e6+10;
ll T,n,m;
struct node
{
	ll t,l,r;
}num[200];
int main(){
	cin>>T;
	while(T--)
    {
		cin>>n>>m;
		ll minn=m,maxx=m;
		bool flag=0;
		num[0].t=0;
		for(int i=1;i<=n;i++)
		{
			cin>>num[i].t>>num[i].l>>num[i].r;
			ll cul=num[i].t-num[i-1].t;
			ll temp1=minn-cul,temp2=maxx+cul;
			if(temp1>num[i].r || temp2<num[i].l) flag=1;
			minn=max(minn-cul,num[i].l);
			maxx=min(maxx+cul,num[i].r);
		}
		if(flag) 
            puts("NO");
		else 
            puts("YES");
	}
	
	return 0;
}

D. Shortest and Longest LIS

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int n,t;
void Codeforce()
{
    scanf("%d",&n);
    cin >> s;
    int total = 0, ans = n;
    for(int i=0;i<=n-2;i++)
    {
        if (s[i] == '<')
            total++;
        else
        {
            for(int i=ans-total;i<=ans;i++)
                cout << i << " ";
            ans = ans - total - 1;
            total = 0;
        }
    }
    for (int i = ans - total ; i <= ans && i >= 1 ; i ++)
        cout << i << " ";
    cout << '\n';
    
    total = 0;
    ans = 1;
    for(int i=0;i<=n-2;i++)
    {
        if (s[i] == '>')
            total++;
        if (s[i] == '<')
        {
            for(int i=ans+total;i>=ans;i--)
                cout << i << " ";
            ans = ans + total + 1;
            total = 0;
        }
    }
    for (int i = ans + total; i >= ans && i <= n; i--)
        cout << i << " ";
    puts("");
}
int main()
{
	scanf("%d",&t);
	while (t--)
	{
		Codeforce();
	}
	return 0;
}
©️2020 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值