Codeforces Round #620 (Div. 2)

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;
}


02-18 284

02-16 311

02-16 169

02-15 328

02-16 284

02-16 54

02-17 130

【Codeforces Round#620 (Div. 2)】B. Longest Palindrome 题解

©️2020 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

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