首页 > 其他分享 >Educational Codeforces Round 161 (Rated for Div. 2)

Educational Codeforces Round 161 (Rated for Div. 2)

时间:2024-01-19 19:35:00浏览次数:31  
标签:Educational Rated int sum namespace Codeforces cin ans include

A. Tricky Template

image
image
image
image

思维有点难转过来,而且当时在C也能匹配c这卡了很久

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n;
	cin>>n;
	string a,b,c;
	cin>>a>>b>>c;
	int cnt=0;
	int f=0;
	for(int i=0;i<n;i++){
		if(a[i]!=c[i]&&b[i]!=c[i])f=1;
	}
	if(f){
		cout<<"YES\n";
	}else{
		cout<<"NO\n";
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

B. Forming Triangles

image
image
image
image

两种情况

#include<bits/stdc++.h>
#define  int long long
using namespace std;
const int N=3e5+10;
void solve(){
	int n;
	cin>>n;
	map<int,int>mp;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		mp[x]++;
	}
	int ans=0;
	int sum=0;
	for(auto c:mp){
		int x=c.second;
		if(x>=2)sum+=(x*(x-1))/2;
	}
	for(auto c:mp){
		int x=c.second;
		int u=c.first;
		if(x>=3){
			ans+=(x*(x-1)*(x-2))/6;
		}
		sum-=(x*(x-1))/2;
		ans+=x*sum;
	}
	cout<<ans<<"\n";
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

C. Closest Cities 前缀和

image
image
image

一开始脑子抽了把需要image

image

分开来讨论了,于是用了结构体,但是其实这两个都是花费问题,所以用数组前缀和,到时候直接查就行了

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],l[N],r[N];
void solve(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n-1;i++){
		if(i==1||a[i+1]-a[i]<a[i]-a[i-1])r[i]=1;
		else r[i]=a[i+1]-a[i];
	}
	for(int i=n;i>=2;i--){
		if(i==n||a[i]-a[i-1]<a[i+1]-a[i])l[i]=1;
		else l[i]=abs(a[i-1]-a[i]);
	}
	for(int i=1;i<=n;i++)r[i]+=r[i-1];
	for(int i=n;i>=1;i--)l[i]+=l[i+1];
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		int x,y;
		cin>>x>>y;
		if(x<y){
			cout<<r[y-1]-r[x-1]<<"\n";
		}else{
			cout<<l[y+1]-l[x+1]<<"\n";
		}
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

标签:Educational,Rated,int,sum,namespace,Codeforces,cin,ans,include
From: https://www.cnblogs.com/yufan1102/p/17975444

相关文章

  • Codeforces Round 919 (Div. 2)
    目录写在前面ABCDE写在最后写在前面比赛地址:https://codeforces.com/contest/1920考试周突然发癫想打cf但是觉得肯定打不完所以拿小号打的。手速慢了没上大分呃呃A求出上下界来,再求被限制的数有多少个在区间内即可。///*By:Luckyblock*/#include<bits/stdc++.h>#de......
  • Codeforces Round 920 (Div. 3)
    A.Square#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ inta1,b1,a2,b2,a3,b3,a4,b4; cin>>a1>>b1>>a2>>b2>>a3>>b3>>a4>>b4; ints1,s2; if(a1==a2){ s1=abs(b1-b2); s2=abs(b3-b4); }e......
  • Educational Codeforces Round 161 (Rated for Div. 2)
    题目链接:EducationalCodeforcesRound161(RatedforDiv.2) PS:A开的很快,B读个假题意,C又想歪了,导致E没时间写,最后十分钟开E思路对了但是没时间了,赛后很快过了。。。A.TrickyTemplate题意:定义模板串t与字符串s:1:如果模板串的某一项为小写字母,那么模板串与字符串的该......
  • Educational Codeforces Round 161 (Rated for Div. 2)
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1922D没调出来亏炸了,第一次体验赛后五分钟过题的快感。痛苦的大二上终于结束了,本学期一半的痛苦都来自于傻逼大物实验。下学期课少了好多,而且早八和晚八都少的一批,集中上一波分了就。A题面太长......
  • Codeforces 920 (div3)
    Problem-A-Codeforces没什么问题,几个ifelse语句,判断一下条件;#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;intmain(){intk;cin>>k;while(k--){intx1,y1,x2,y2,x3,y3,x4,y4;......
  • Codeforces edu 161 (div2)
    Problem-A-Codeforces思维题,判断c字符串的每一位是否都能在相对应的a字符串或者b字符串里面找到;如果都能找到的话就输出NO;否则输出YES;#include<bits/stdc++.h>usingnamespacestd;intmain(){std::ios::sync_with_stdio(false);cin.tie(0);cout.tie......
  • Educational Codeforces Round 161 (Rated for Div. 2)
    EducationalCodeforcesRound161(RatedforDiv.2)比赛链接A.TrickyTemplate思路:貌似只要想到了就可以,我是记录了一下字符串c和字符串a和b之间的满足数,如果等于n表示一定不存在,否则就是存在的Code:#include<bits/stdc++.h>usingnamespacestd;#defineintlonglon......
  • CodeForces & AtCoder rating 规则简述
    译者:rui_er,转载请注明出处。(备份自2020年11月2日的同名博客)本博客为了方便自己查阅,同时也方便大家了解,但因为我英语很菜,所以难免有翻译错的地方,还请评论区纠正。未注明资料来源的均为常识积累。1CodeForcesrating规则1.1CodeForcesrating与名字颜色换算设\(r\)......
  • hey_left 8 Codeforces Round 871 (Div. 4)
    题目链接A.直接比较输入字符串和已知字符串有几个不同即可#include<bits/stdc++.h>usingnamespacestd;voidsolve(){strings;cin>>s;intans=0;stringt="codeforces";for(inti=0;i<10;i++){if(s[i]!=t[i])ans++;}cout<&......
  • hey_left 7 Codeforces Round 886 (Div. 4) 续
    题目链接F.记录下出现的数字和个数注意放置陷阱的位置1-n都有可能然后遍历1-n,对每个数进行因子分解,对于在因子的位置上有青蛙的,加上青蛙的个数,取最大即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=2e5+10;voidsolve(){int......