Codeforces Round #485 (Div. 2)
Codeforces Round #485 (Div. 2)
https://codeforces.com/contest/987
A
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; map<string,string>mp;
int main(){
std::ios::sync_with_stdio(false);
int n;
cin>>n;
string s[];
mp["purple"]="Power";
mp["green"]="Time";
mp["blue"]="Space";
mp["orange"]="Soul";
mp["red"]="Reality";
mp["yellow"]="Mind";
for(int i=;i<n;i++){
cin>>s[i];
mp[s[i]]="";
}
cout<<-n<<endl;
for(auto it:mp){
if(it.second!="") cout<<it.second<<endl;
}
}
B
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; map<string,string>mp;
int main(){
std::ios::sync_with_stdio(false);
ll x,y;
cin>>x>>y;
if(x==y||(x==&&y==)||(x==&&y==)){cout<<"="<<endl;return ;}
if(x==&&y==||x==){cout<<"<"<<endl;return ;}
if(x==&&y==||y==){cout<<">"<<endl;return ;}
else if(x<y){cout<<">"<<endl;return ;}
else if(x>y){cout<<"<"<<endl;return ;}
return ;
}
C
题意:给n个数,每个位置有两个属性s,c,要求选择3个位置i,j,k,i<j<k且si<sj<sk 且ci+cj+ck的值最小
思路:原本想了个三重for循环暴力,但是看了数据觉得不可行,然后发现,如果枚举中间那个数j,那么i往前枚举,k往后枚举,这样只要O(n^2)的时间复杂度,可以通过该题
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int n;
struct sair{
int pos,v;
bool operator<(const sair&b)const{
return pos<b.pos;
}
}a[];
vector<sair>ve; int main(){
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i].pos;
}
for(int i=;i<=n;i++){
cin>>a[i].v;
}
ll ans=0x3f3f3f3f3f3f3f3f;
for(int i=;i<n;i++){
ll Min1=0x3f3f3f3f3f3f3f3f,Min2=0x3f3f3f3f3f3f3f3f;
int posl=i-,posr=i+;
while(posl>=){
if(a[posl].pos<a[i].pos){
if(Min1>a[posl].v){
Min1=a[posl].v;
}
}
posl--;
}
while(posr<=n){
if(a[posr].pos>a[i].pos){
if(Min2>a[posr].v){
Min2=a[posr].v;
}
}
posr++;
}
if(Min1!=0x3f3f3f3f3f3f3f3f&&Min2!=-0x3f3f3f3f3f3f3f3f){
ans=min(ans,Min1+Min2+a[i].v);
}
}
if(ans==0x3f3f3f3f3f3f3f3f) cout<<-<<endl;
else cout<<ans<<endl;
}
D
题意:一些公司将在某地举办展览会,该地有n个城市,有m条双向道路。有k种类型的物品,每个城市可以生产出一个类型的物品。举办展览会需要有s种物品。每种物品运输需要一定的费用,费用等于路径的长度,问在n个城市举办展览会的最少费用
思路:把每种物品跑最短路即可
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 5000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int n,m,s,k;
int a[];
vector<int>ve[];
int book[];
int dis[][]; void bfs(){
queue<int>Q;
memset(dis,-,sizeof(dis));
for(int i=;i<=s;i++){
while(!Q.empty()) Q.pop();
for(int j=;j<=n;j++){
if(a[j]==i){
Q.push(j);
dis[j][i]=;
}
}
while(!Q.empty()){
int ss=Q.front();
Q.pop();
for(auto au:ve[ss]){
if(dis[au][i]==-){
dis[au][i]=dis[ss][i]+;
Q.push(au);
}
}
}
}
ll ans;
for(int i=;i<=n;i++){
ans=;
sort(dis[i]+,dis[i]+s+);
for(int j=;j<=k;j++){
ans+=dis[i][j];
}
cout<<ans<<" ";
}
} int main(){
std::ios::sync_with_stdio(false);
cin>>n>>m>>s>>k;
for(int i=;i<=n;i++){
cin>>a[i];
}
int x,y;
for(int i=;i<=m;i++){
cin>>x>>y;
ve[x].pb(y);
ve[y].pb(x);
}
bfs();
}
E
题意:有1-n按顺序排列的数,A进行3*n操作,每次交换两个数,B进行7*n+1操作,给个1-n的排列,问是谁打乱的
思路:每次交换逆序对都会加一或减一,且从一个序列变回该序列需要至少两次操作,所以判断逆序对和n的奇偶性即可
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 5000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int n;
int a[];
int tree[]; int lowbit(int x){return x&(-x);}
int ask(int x){int ans=;while(x){ans+=tree[x];x-=lowbit(x);}return ans;}
void add(int x){while(x<=n){tree[x]+=;x+=lowbit(x);}} int main(){
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i];
}
int sum=;
for(int i=n;i;i--){
sum+=ask(a[i]);
add(a[i]);
}
sum&=,n&=;
if(sum==n) cout<<"Petr"<<endl;
else cout<<"Um_nik"<<endl;
}
F
题意:有m个整数,每个整数都在0~2^n-1之间,以每个整数为顶点建立一个无向图,当x&y==0时,则认为x,y之间存在一条边。计算图中联通块的数量。
思路:1010和0101符合条件,那1010和0001,0100,0000也符合条件,所以当一个数为x时,直接找~x(就是x转二进制后每位数与1异或后的值)的子集,然后搜索找联通块即可
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<ll>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 5000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int n,m;
int book[maxn],a[maxn],num[maxn]; void bfs(int x){
queue<int>Q;
Q.push(x);
book[x]=;
while(!Q.empty()){
int s=Q.front();
// cout<<s<<endl;
Q.pop();
for(int i=;i<n;i++){
if(s&(<<i)){
int tmp=s-(<<i);
if(!book[tmp]){
book[tmp]=;
Q.push(tmp);
if(num[tmp]){
tmp=(<<n)--tmp;
if(!book[tmp]){
book[tmp]=;
Q.push(tmp);
}
}
}
}
}
}
} int main(){
std::ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<=m;i++){
cin>>a[i];
num[a[i]]=;
}
int ans=;
for(int i=;i<=m;i++){
if(!book[a[i]]){
ans++;
book[a[i]]=;
int tmp=(<<n)--a[i];
bfs(tmp);
}
}
cout<<ans<<endl;
}
Codeforces Round #485 (Div. 2)的更多相关文章
- Codeforces Round #485 (Div. 2) D. Fair
Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #485 (Div. 2) E. Petr and Permutations
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...
- Codeforces Round #485 (Div. 2) C. Three displays
Codeforces Round #485 (Div. 2) C. Three displays 题目连接: http://codeforces.com/contest/987/problem/C D ...
- Codeforces Round #485 (Div. 2) A. Infinity Gauntlet
Codeforces Round #485 (Div. 2) A. Infinity Gauntlet 题目连接: http://codeforces.com/contest/987/problem/ ...
- Codeforces Round #485 (Div. 2)-B-High School: Become Human
B. High School: Become Human time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #485 (Div. 2) C题求三元组(思维)
C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #485 Div. 1 vp记
A:对每种商品多源bfs一下每个点到该商品的最近距离,对每个点sort一下取前s个即可. #include<iostream> #include<cstdio> #includ ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- 转HDMI
HDMI协议解析 2017年06月18日 14:19:27 阅读数:2987 转载请标明出处floater的csdn blog,http://blog.csdn.net/flaoter 本文从软件工程 ...
- 再说项目 Dec 27th 2018
其实对于任何项目来说,最难不是开发或者系统等技术的问题,反而是需求的问题,需求一直变,一直定不下来,导致流程变来变去,系统方案层面也确定不下来.而需求的问题,归根结底还是人的问题.项目的关键用户对现有 ...
- SQL修改某个字段中某相同部分(MySQL)
格式:UPDATE 表名 SET 字段名= REPLACE( 替换前的字段值, '替换前关键字', '替换后关键字' ) WHERE 条件;比如:update t_book SET book_no ...
- DLC 格雷码
格雷码特点 每相邻两个数,只会有一位发生变(二进制数) 异或运算 若两个运算数相同,结果为 0 若两个运算数不相同, 结果为 1
- Linux 打包压缩与搜索命令
1.tar 用于对文件进行打包压缩或解压,格式为tar[选项][文件],-f参数必须放到参数最后一位 tar -czvf etc.tar.gz /etc tar参数及作用 参数 作用 -c 创建压缩文 ...
- Zabbix11.3 Zabbix SNMP 常用OID列表
点击获取CISCO设备OID 系统参数(1.3.6.1.2.1.1) OID 描述 备注 请求方式 .1.3.6.1.2.1.1.1.0 获取系统基本信息 SysDesc GET .1.3.6.1.2 ...
- pgsql 常用命令
1.连接到pgsql数据库 psql -U postgres 2.查看所有数据库 \l 3.连接到数据库test \c test 4.查看数据库所有表以及视图 \d 5.查看数据库所有的表 \dt 6 ...
- 接口性能测试(Jmeter)操作总结
以前常用SoapUI来做接口的性能测试,这次用的Jmeter,对需由客户端根据时间戳等登录参数生成随机token值和印签值来发请求的系统,非它莫属了.下面就这次测试的难点和操作注意问题展开总结. ** ...
- thinkphp5.1 的else if的使用方法
首先thinkphp5.1获取session值是 {$think.session.user_id}或者{$Request.session.user_id}来获取session 下面是if else 的 ...
- 基于SpringBoot+Mybatis+AntDesign快速开发平台,Jeecg-Boot 1.1 版本发布
Jeecg-Boot 1.1 版本发布,初成长稳定版本 导读 平台首页UI升级,精美的首页支持多模式 提供4套代码生成器模板(支持单表.一对多) 集成Excel简易工具类,支持单表.一对多导入 ...