当前位置: 首页 > article >正文

AtCoder Beginner Contest 371

A - Jiro :

题目:

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL ;
typedef pair<int,int> PII;

void solve()
{
    string a,b, c;
    cin>>a>>b>>c;
    string s(3,'a');
    s[0]=a[0];
    s[1]=b[0];
    s[2]=c[0];
    
    // a b c
    // c b a
    // b a c
    // c a b 
    // a c b 
    // b c a
    if(s[0]=='>' && s[1]=='>' && s[2]=='>') cout<<'B';
    else if(s[0]=='<' && s[1]=='<' && s[2]=='<') cout<<'B';
    else if(s[0]=='<' && s[1]=='>' && s[2]=='>') cout<<'A';
    else if(s[0]=='>' && s[1]=='<' && s[2]=='<') cout<<'A';
    else cout<<'C';

}

int main()
{
    int T;
    // cin>>T;
    T=1;
    while(T--){
        solve();
    }
    return 0;
}

B - Taro

题目:

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL ;
typedef pair<int,int> PII;

void solve()
{
	int n,m;
	cin>>n>>m;
	vector<int> a(m);
	string b(m,' ');
	vector<int> h(n);
	for(int i=0; i<m; i++){
		cin>>a[i]>>b[i];
		a[i]--;
		if(b[i]=='M'){
			h[a[i]]++;
		}
		if(h[a[i]]==1 &&b[i]=='M') cout<<"Yes\n";
		else cout<<"No\n";
	}


}

int main()
{
    int T;
    // cin>>T;
    T=1;
    while(T--){
        solve();
    }
    return 0;
}

C - Make Isomorphic:

题目:

思路:

找到g i 与 h j 顶点的对应关系,枚举(1,..,n) 的全排列,计算每种排列对应的花费,取最小值.

代码:

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

typedef long long LL;
typedef pair<int,int> PII;

void solve()
{
	int n;
	cin>>n;
	vector w(n,vector(n,0)),g(n,vector(n,0)), h(n,vector(n,0));
	
	int mg;
	cin>>mg;
	for(int i=0;i <mg; i++){
		int a, b;
		cin>>a>>b;
		a--, b--;
		g[a][b]=1;
		g[b][a]=1;
	}
	int mh;
	cin>>mh;
	for(int i=0; i<mh; i++){
		int a,b;
		cin>>a>>b;
		a--, b--;
		h[a][b]=1;
		h[b][a]=1;
	}
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			cin>>w[i][j];
		}
	}
	vector<int> p(n);
	iota(p.begin(),p.end(),0);
	int ans=1e9;
	do{
		int res=0;
		for(int i=0;i<n; i++){
			for(int j=i+1; j<n; j++){
				if(h[i][j]!=g[p[i]][p[j]]){
					res+=w[i][j];
				}
			}
		}
		ans=min(ans,res);
	}while(next_permutation(p.begin(),p.end()));
	
	cout<<ans<<"\n";
	
}

int main()
{
	int T;
//	cin>>T;
	T=1;
	while(T--){
		solve();
	}
	return 0;
}

D - 1D Country:

题目:

思路:

离散化+二分查找

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
    int n;
    cin>>n;
    vector<int> x(n+1), p(n+1);
    x[0]=-0x3f3f3f3f;
    for(int i=1; i<=n; i++) cin>>x[i];
    for(int i=1; i<=n; i++) cin>>p[i];

    vector<LL> s(n+1);
    for(int i=1; i<=n; i++){
        s[i]=s[i-1]+p[i];
    }
    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        int l=lower_bound(x.begin(), x.end(), a)-x.begin();
        int r=upper_bound(x.begin(), x.end(), b)-x.begin()-1;
        cout<<s[r]-s[l-1]<<'\n';
    }
    
    return 0;
}

E - I Hate Sigma Problems 

题目:

思路:

求每个Ai的贡献,

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
    int n;
    cin>>n;
    vector<int> a(n+1);
    vector<vector<int>> pos(n+1);
    for(int  i=1; i<=n; i++){
        cin>>a[i];
        pos[a[i]].push_back(i);
    } 
    LL ans=0;
    for(int i=1; i<=n; i++){
        int ls=0;
        for(auto j: pos[i]) ans+=1LL*(j-ls)*(n-j+1), ls=j;
    }
    cout<<ans<<'\n';
}


http://www.kler.cn/news/312058.html

相关文章:

  • 在SpringCloud中实现服务熔断与降级,保障系统稳定性
  • vue2中字符串动态拼接字段给到接口
  • 机器学习(西瓜书)第 14 章 概率图模型
  • 程序员的养生
  • NET WPF使用组件库HandyControl
  • Github 2024-09-14 Rust开源项目日报Top10
  • 傅里叶变换
  • vim 操作一列数字
  • 【天怡AI-注册安全分析报告-无验证方式导致安全隐患】
  • javascript 浏览器打印不同页面设置方向,横向纵向打印
  • CPLEX+Yalmip+MATLAB2022a配置
  • 【贪心算法】贪心算法一
  • vue前端调起电脑应用并且检测有没有调用成功
  • 人工智能将来好就业吗?
  • LINUX的PHY抽象层——PAL
  • Qt/C++ 了解NTFS文件系统,解析盘符引导扇区数据获取MFT(Master File Table)主文件表偏移地址
  • 服务发现和代理实例的自动更新
  • Linux 基本使用和 web 程序部署 ( 8000 字 Linux 入门 )
  • 【python】后台程序初始化全流程
  • electron-vue安装与打包问题解决
  • js中箭头函数与普通函数的区别
  • 删除视频最后几帧 剪切视频
  • Vue3:el-table实现日期的格式化
  • 安卓 uniapp跨端开发
  • JVM 内存模型:堆、栈、方法区讲解
  • 如何使用Postman搞定带有token认证的接口实战!
  • VSCode C++ Tasks.json中的变量
  • 住宅HTTP代理:提升网络隐私与安全的新选择
  • Electron-vue asar 局部打包优化处理方案——绕开每次npm run build 超级慢的打包问题
  • 1.MySQL在Centos 7环境安装