当前位置:网站首页>Codeforces Round #800 (Div. 2)
Codeforces Round #800 (Div. 2)
2022-06-26 05:03:00 【ccsu_ yuyuzi】
A. Creep
Problem - A - Codeforces
https://codeforces.com/contest/1694/problem/A Sign in , Don't talk about ideas
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;
void solve()
{
int a,b;
cin>>a>>b;
//a0,b1
if(a>=b)
{
for(int i=0;i<b;i++)
cout<<"01";
for( int i=0;i<a-b;i++)
cout<<"0";
cout<<"\n";
return;
}
else if(a<b)
{
for(int i=0;i<a;i++)
cout<<"01";
for( int i=0;i<b-a;i++)
cout<<"1";
cout<<"\n";
return;
}
return;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}B. Paranoid String
Problem - B - Codeforces
https://codeforces.com/contest/1694/problem/B The question : Here's a string for you . There are two operations , Put the adjacent "01" Turn into "1', Or the "10" become "0", Ask how many substrings can be changed into a number after the operation .
After we set the watch , Will find , As long as the last two letters are different , All previous characters can be deleted , conversely , Do not place .
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;
const int N =5e5+10,mod=998244353;
void solve()
{
int n,ans=0;
string s;
cin>>n>>s;
ans=s.size();
for(int i=1;i<s.size();i++)
{
if(s[i]!=s[i-1])
ans+=i-1+1;
}
cout<<ans<<"\n";
return ;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}C. Directional Increase
Problem - C - Codeforces
https://codeforces.com/contest/1694/problem/C The question : We from 0 set out , Take a step to the right , So the weight of the place we were in +1, Take a step to the left to get the weight of the original place -1. Give you an array after the operation , Ask to return to the starting point after a series of operations , Can I get this array .
Want negative numbers on the right , So what is certain is that we must come from the left , So what is the negative number on the right , We must make sure that the positive value to the left of the path is its negative value , The two add up to 0( Because I have to walk back at last , The steps left and right are the same ). Then we can draw a conclusion , Find the prefix and of the array , Make sure that the last one is 0, The rest of the prefixes and must be >0.( Of course , We should put the following continuous 0 Get rid of , Because I didn't go to these parts ).
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;
const int N =5e5+10,mod=998244353;
void solve()
{
int n,ans=0;
string s;
cin>>n>>s;
ans=s.size();
for(int i=1;i<s.size();i++)
{
if(s[i]!=s[i-1])
ans+=i-1+1;
}
cout<<ans<<"\n";
return ;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}D. Fake Plastic Trees
Problem - D - Codeforces
https://codeforces.com/contest/1694/problem/D The question : Give you a tree , The weight at the beginning of each point is 0, We can choose a point first v, And operate to make the root node 1 To this point v Add an increasing array to the weight of points on the path of . Ask to ensure that the weight of each point after the final operation is within the given range of the topic l,r( The array given by the title , Are the lower and upper bounds of the weight of the point respectively ) The minimum number of operation steps required .
We want to ensure that each point reaches the interval , You can try to be greedy , We try to make each node reach its maximum value , So when dealing with their parent nodes , It must be adding up all the values of the child nodes , This sum is the weight of the point obtained by our parent node without redundant operations after the operation of the child node . When this weight is less than the lower bound , One more step is needed , Make it eligible , conversely , Because it's greed , We can change the weight of the point into the minimum value of the child node weight and the upper bound of the point .( The root node must do one step , And take its upper bound ).
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;
struct node
{
int to,ne;
}edge[400005];
int h[200005],ans,tot,f[200005],cnt,l[200005],r[200005];
void add(int x,int y)
{
edge[++tot].to=y;
edge[tot].ne=h[x];
h[x]=tot;
return ;
}
void dfs(int x)
{
int sum=0;
for(int i=h[x];i!=-1;i=edge[i].ne)
{
int y=edge[i].to;
dfs(y);
sum+=f[y];
}
if(sum<l[x])
{
ans++;
f[x]=r[x];
}
else
{
f[x]=min(sum,r[x]);
}
}
void solve()
{
ans=0,tot=0;
memset(h,-1,sizeof h);
int n,x;
scanf("%lld",&n);
for(int i=2;i<=n;i++)
{
scanf("%lld",&x);
add(x,i);
}
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&l[i],&r[i]);
}
dfs(1);
printf("%lld\n",ans);
return ;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}边栏推荐
猜你喜欢

The first gift of the project, the flying oar contract!

What is UWB in ultra-high precision positioning system

PSIM software learning ---08 call of C program block

2022.2.11

Using requests library and re library to crawl web pages

【Latex】错误类型总结(持更)

1.16 learning summary

Machine learning final exercises

UWB ultra high precision positioning system architecture
![C# 40. byte[]与16进制string互转](/img/3e/1b8b4e522b28eea4faca26b276a27b.png)
C# 40. byte[]与16进制string互转
随机推荐
Multipass中文文档-与实例共享数据
Rsync common error messages (common errors on the window)
Day4 branch and loop jobs
86. (cesium chapter) cesium overlay surface receiving shadow effect (gltf model)
NVM installation and use and NPM package installation failure record
Computer Vision Tools Chain
Numpy data input / output
Multipass中文文档-使用Packer打包Multipass镜像
PHP之一句话木马
A company crawling out of its grave
A ZABBIX self discovery script (shell Basics)
Happy New Year!
超高精度定位系统中的UWB是什么
Datetime data type ---now() gets the current time, datetime() creation date, performs mathematical operations, and to_ Datetime() converts to date type and extracts various parts of date
UWB超高精度定位系统原理图
dijkstra
一个从坟墓里爬出的公司
Difference between return and yield
【Unity3D】刚体组件Rigidbody
File upload and security dog