当前位置:网站首页>Codeforces Round #620 (Div. 2)ABC
Codeforces Round #620 (Div. 2)ABC
2022-06-23 16:35:00 【leimingzeOuO】
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;
}
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;
}
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;
}
边栏推荐
- QT当中的【QSetting和.ini配置文件】以及【创建Resources.qrc】
- 以 27K 成功入职字节跳动,这份《 软件测试面试笔记》让我受益终身
- NLP paper reading | improving semantic representation of intention recognition: isotropic regularization method in supervised pre training
- Here comes the official zero foundation introduction jetpack compose Chinese course!
- R language ggplot2 visualizes horizontal boxplot with coord_flip, and adds jittered data points to display the distribution
- ABAP随笔-程序优化笔记
- Taishan Office Technology Lecture: four cases of using Italic Font
- DataNode进入Stale状态问题排查
- Huawei mobile phones install APK through ADB and prompt "the signature is inconsistent. The application may have been modified."
- A number of individual stocks in Hong Kong stocks performed actively, triggering investors' speculation and concern about the recovery of the Hong Kong stock market
猜你喜欢

Shushulang passed the listing hearing: the gross profit margin of the tablet business fell, and the profit in 2021 fell by 11% year-on-year

Golang writes to JSON files

Stick to five things to get you out of your confusion

ASEMI肖特基二极管和超快恢复二极管在开关电源中的对比

JS common error reporting and exception capture

Robot Orientation and some misunderstandings in major selection in college entrance examination
NLP paper reading | improving semantic representation of intention recognition: isotropic regularization method in supervised pre training

IFLYTEK neuroimaging disease prediction program!

DataNode进入Stale状态问题排查

图扑数字孪生 3D 风电场,智慧风电之海上风电
随机推荐
ABAP随笔-物料主数据界面增强
谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
ASEMI快恢复二极管RS1M、US1M和US1G能相互代换吗
ABAP essays - program optimization notes
R language uses colorblinr package to simulate color blind vision, and uses edit to visualize the image of ggplot2_ The colors function is used to edit and convert color blindness into visual results
你的PCB地线走的对吗?为什么要有主地?
Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
The R language uses the GT package and the gtextras package to display tabular data gracefully and beautifully: gt of the gtextras package_ The sparkline function visualizes the line plot of the group
ELK日志收集系统部署
Innovative technology leader! Huawei cloud gaussdb won the 2022 authoritative award in the field of cloud native database
Amadis publishes Ola payment processing standards
What does websocket do?
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 2)
Can the asemi fast recovery diodes RS1M, us1m and US1G be replaced with each other
Leetcode 450. Delete node in binary search tree
【网络通信 -- WebRTC】WebRTC 源码分析 -- 接收端带宽估计
Coatnet: marrying revolution and attention for all data sizes
Thinking analysis of binary search method
WebSocket能干些啥?
测试的重要性及目的