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)的更多相关文章

  1. Codeforces Round #485 (Div. 2) D. Fair

    Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description ...

  2. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  3. Codeforces Round #485 (Div. 2) E. Petr and Permutations

    Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...

  4. Codeforces Round #485 (Div. 2) C. Three displays

    Codeforces Round #485 (Div. 2) C. Three displays 题目连接: http://codeforces.com/contest/987/problem/C D ...

  5. Codeforces Round #485 (Div. 2) A. Infinity Gauntlet

    Codeforces Round #485 (Div. 2) A. Infinity Gauntlet 题目连接: http://codeforces.com/contest/987/problem/ ...

  6. 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 ...

  7. Codeforces Round #485 (Div. 2) C题求三元组(思维)

    C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. Codeforces Round #485 Div. 1 vp记

    A:对每种商品多源bfs一下每个点到该商品的最近距离,对每个点sort一下取前s个即可. #include<iostream> #include<cstdio> #includ ...

  9. 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 ...

随机推荐

  1. crf++实现中文分词简单例子 (Windows crf++0.58 python3)

    学习自然语言处理的同学都知道,条件随机场(crf)是个好东西.虽然它的原理确实理解起来有点困难,但是对于我们今天用到的这个crf工具crf++,用起来却是挺简单方便的. 今天只是简单试个水,参考别人的 ...

  2. 3阶马尔可夫链 自然语言处理python

    一.简介:       把每三个三个单词作为一个整体进行训练. 举一个例子: input:       my dream is that I can be an engineer, so I desi ...

  3. Oracle数据库自带表空间的详细说明

    1.SYSAUX表空间 SYSAUX表空间在Oracle Database 10g中引入,作为SYSTEM表空间的辅助表空间.以前一些使用独立表空间或系统表空间的数据库组件现在在SYSAUX表空间中创 ...

  4. .net core2 api

    [Produces("application/json")][Consumes("application/json")][Consumes("appl ...

  5. Pandas学习笔记(二)

    (1)Pandas处理以下三个数据结构 系列(Series) 数据帧(DataFrame) 面板(Panel) 这些数据结构构建在Numpy数组之上,这意味着它们很快.考虑这些数据结构的最好方法是,较 ...

  6. 使用yum安装 gdb/g++等软件包

    报错: Cannot find a valid baseurl for repo: base/7/x86_6 解决方法: 方法一. 1.打开 vi /etc/sysconfig/network-scr ...

  7. 错误 88 error C2248: “CObject::CObject”: 无法访问 private 成员(在“CObject”类中声明) c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afxcoll.h 590

    最近接收了以前新公司遗留的代码,一个函数动不动就少的一千行,多的几千行,真是受不了这编码风格! 于是便使用了VS自带的重构工具,选择代码后右键-重构-提取方法,提取完方法就编译不过,想了好久原因,原来 ...

  8. Linux高级指令

    一.hostname指令 作用:操作服务器的主机名(读取,设置) #hostname    作用:表示输出完整的主机名 #hostname -f    作用:表示输出当前主机名中的FQDN(权限定域名 ...

  9. shell脚本实现telnet测试服务端口

    备注,使用方法:当前目录下要存在需要测试的地址端口的文件ip.txt,例子:cat ip.txt141.12.65.17 7500 #!/bin/bashcur_dir=$(pwd)ipfile=$c ...

  10. k8s外部访问内部的service

    如果不指定Service的spec.type的值,创建的Service的类型默认为ClusterIP类型.这种类型的Service只会得到虚拟的IP和端口,只能在Kubernetes集群内部被访问. ...