前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AtCoder Beginner Contest 162 A~~D

AtCoder Beginner Contest 162 A~~D

作者头像
杨鹏伟
发布2020-09-11 08:02:07
2550
发布2020-09-11 08:02:07
举报
文章被收录于专栏:ypw

A 水题:用字符串就很好处理

代码语言:javascript
复制
#include<bits/stdc++.h>

using namespace std;

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i] == '7'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
} 

B. 水题

代码语言:javascript
复制
#include<bits/stdc++.h>

using namespace std;

int main(){
	long long  n;
	cin>>n;
	long long  sum = 0;
	for(long long  i=1;i<=n;i++){
		if(i%3==0&&i%5==0){
			continue;
		}
		if(i%3==0){
			continue;
		}
		if(i%5==0){
			continue;
		}
		sum += i;
	}
	cout<<sum<<endl;
	return 0;
}

C 水题:暴力就行

代码语言:javascript
复制
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
	ll k;
	cin>>k;
	ll sum = 0;
	ll res;
	for(ll i=1;i<=k;i++){
		for(ll j=1;j<=k;j++){
			for(ll s=1;s<=k;s++){
				res = __gcd(i,j);
				res = __gcd(res,s);
				//cout<<res<<"--";
				sum += res;
			}
		}
	}
	//cout<<endl;
	cout<<sum<<endl;
	return 0;
} 

D 思路:暴力肯定会超时,我采用二分,然后不知道怎么W了两个点

代码语言:javascript
复制
#include<bits/stdc++.h>

using namespace std;

int  R[4005];
int  G[4005];
int B[4005];

int main(){
	int l;
	cin>>l;
	string s;
	cin>>s;
	int tot = 0;
	int res;
	int num1=0;
	int num2=0;
	int num3=0;
	for(int i=0;i<l;i++){
		if(s[i] == 'R'){
			R[num1] = i;
				num1++;
		} 
		if(s[i] == 'G'){
			G[num2] = i;
				num2++;
		} 
		if(s[i] == 'B'){
		B[num3] = i;	
		num3++;
		} 
	}
	if(num1==0||num2==0||num3==0) {
		cout<<"0"<<endl;
	}
	else{
		int num;
		int i,j;
		for(int i=0;i<=l-3;i++){
			for(int j=i+1;j<=l-2;j++){
				if(s[i]=='R'&&s[j]=='G'){
					res = (upper_bound(B,B+num3,j) - B);
					tot += num3 - res;
					if(binary_search(B,B+num3,2*j-i))  tot--;
				}
				if(s[i]=='G'&&s[j]=='R'){
					res = (upper_bound(B,B+num3,j) - B);
					tot += num3 - res;
					if(binary_search(B,B+num3,2*j-i)) tot--;
				}
				if(s[i]=='R'&&s[j]=='B'){
					res = (upper_bound(G,G+num2,j) -G);
					tot += num2 - res;
					if(binary_search(G,G+num2,2*j-i)) tot--;
				}
				if(s[i]=='B'&&s[j]=='R'){
					res = (upper_bound(G,G+num2,j) -G);
					tot += num2 - res;
					if(binary_search(G,G+num2,2*j-i)) tot--;
				}
				if(s[i]=='G'&&s[j]=='B'){
					res = (upper_bound(R,R+num1,j) -R);
					tot += num1 - res;
					if(binary_search(R,R+num1,2*j-i)) tot--;
				}
				if(s[i]=='B'&&s[j]=='G'){
					res = (upper_bound(R,R+num1,j) -R);
					tot += num1 - res;
					if(binary_search(R,R+num1,2*j-i)) tot--;
				}
			
			}
		}
		cout<<tot<<endl;
	}

	return 0;
}

AC代码

代码语言:javascript
复制
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(void){
    int N; cin >> N;
    string S; cin >> S;
    
    ll r=0, g=0, b=0;
    for (auto c : S){
        if (c=='R') r++;
        if (c=='G') g++;
        if (c=='B') b++;
    }
    
    ll ans = r * g * b;
    for (int d = 1; d <= N; d++){
        for (int m = 1; m < N-1; m++){
            if (m-d<0||m+d>N-1) continue;
            if (S[m-d]!=S[m+d] && S[m-d]!=S[m] && S[m]!=S[m+d]) ans--;
        }
    }
    cout << ans << endl;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/04/13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档