Codeforces Round 928 (Div. 4)(A-G)

A:Vlad and the Best of Five

模拟比较a,b多少

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 500100
string s;
int  a[N],p[N];
vector<int>g[N];
const int mod=1e9+7;

void solve(){
	string s;
	cin>>s;
	int ans=0;
	for(auto x:s) {
		if(x=='A' ) ans++;
		else ans--;
	}
	if(ans>0) cout<<"A"<<endl;
	else cout<<"B"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
    	solve();
	}
}

B:Vlad and Shapes

判断是三角形还是正方形,如果有一行或者一列是1则为三角形

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 500100
string s;
int  a[N],p[N];
vector<int>g[N];
const int mod=1e9+7;

void solve(){
   int n;
   cin>>n;
   string s[11];
   for(int i=0;i<n;i++) cin>>s[i];
   int flag=0;
   for(int i=0;i<n;i++){
   	  int sum=0;
   	  for(int j=0;j<n;j++) {
   	     if(s[i][j]=='1') sum++;  	
	 }
	 if(sum==1) flag=1;
   }
   for(int i=0;i<n;i++){
   	  int sum=0;
   	  for(int j=0;j<n;j++) {
   	     if(s[j][i]=='1') sum++;  	
	 }
	 if(sum==1) flag=1;
   }
   if(flag) cout<<"TRIANGLE"<<endl;
   else cout<<"SQUARE"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
    	solve();
	}
}

C:Vlad and a Sum of Sum of Digits

提前预处理就行,前缀和

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 500100
string s;
int  a[N],p[N];
vector<int>g[N];
const int mod=1e9+7;

int cal(int n){
	int res=0;
	while(n){
		res+=n%10;
		n/=10;
	}
	return res;
}
void init(){
	for(int i=1;i<=200100;i++){
		a[i]=a[i-1]+cal(i);
	}
}
void solve(){
    int n;
    cin>>n;
    cout<<a[n]<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    init();
    while(t--){
    	solve();
	}
}

D:Vlad and Division

记录每个数的出现次数,用map存,之后统计

a[i]^1<<31-1如果两个都不为0,则减去,res++,在统计没有匹配的数

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 500100
string s;
int  a[N],p[N];
vector<int>g[N];
const int mod=1e9+7;


void solve(){
   int n;
   cin>>n;map<int,int>m;
   for(int i=0;i<n;i++) cin>>a[i],m[a[i]]++;
   
   int res=0;
   for(int i=0;i<n;i++){
   	    int g=a[i]^((1ll<<31)-1ll);
   	    if(m[a[i]]&&m[g]){
   	          res++;
			  m[a[i]]--;
			  m[g]--;	
		}
   }
   for(auto x:m) res+=x.second;
   cout<<res<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
    	solve();
	}
}

E:Vlad and an Odd Ordering

先打表发现只有在2的次方下才会删除数字

这样我们直接枚举即可

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
int a[N],b[N];
void solve(){
    int n,k;
    cin>>n>>k;
    int g=ceil(1.0*n/2);
    if(k<=g)cout<<2*k-1<<endl;//先删去奇数
	else{
		k-=g;//剩余位置
		int mod=2;//二的倍数枚举
		while(true){
			g=n/mod;
			if(g%2==0) g--;
			g=(g+1)/2;
			if(k>g){
				k-=g;
				mod*=2;
				continue;
			}
			else {
				cout<<mod*(2*k-1)<<endl;
				return ;
			}
		}
	}
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

G:Vlad and Trouble at MIT

c的话当成s或p 来动态规划

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
int a[N],b[N];
vector<int>g[N];
int f[N][3];
string s;
void dfs(int u){
	f[u][0]=f[u][1]=0;
	if(s[u]=='P') f[u][0]=0x3f3f3f3f;//
	if(s[u]=='S') f[u][1]=0x3f3f3f3f;
	for(auto x:g[u]){
		dfs(x);
		f[u][0]+=min(f[x][0],f[x][1]+1);
		f[u][1]+=min(f[x][1],f[x][0]+1);
	}
}
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) g[i].clear();
    for(int i=2;i<=n;i++) {
    	int x;
    	cin>>x;
    	g[x].push_back(i);
    }
    cin>>s;
    s=' '+s;
    dfs(1);
    cout<<min(f[1][0],f[1][1])<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多年以后

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值