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 ...
随机推荐
- IDEA右侧 Maven oracle依赖包有红色波浪线
1\下载 ojdbc14-10.2.0.4.0.jar http://www.java2s.com/Code/Jar/o/Downloadojdbc14102040jar.htm 2.将ojdbc14 ...
- Docker容器开机自动启动
部署项目服务器时,为了应对停电等情况影响正常web项目的访问,会把Docker容器设置为开机自动启动. 在使用docker run启动容器时,使用--restart参数来设置: # docker r ...
- 在Spring Boot中使用 @ConfigurationProperties 注解
但 Spring Boot 提供了另一种方式 ,能够根据类型校验和管理application中的bean. 这里会介绍如何使用@ConfigurationProperties.继续使用mail做例子. ...
- SSD 的介绍 -------转载
本文转载自: http://www.sohu.com/a/258190629_494938 背景 SSD(Solid-State Drive)是目前正处于鼎盛时期的存储设备.相较于传统的硬盘存储器 ...
- springboot学习二:配置文件配置
springboot默认读取application*.properties #######spring配置####### spring.profiles.active=dev //引入开发配置文件 a ...
- Jquery取小数后边2位,N位;jQuery去掉字符串首尾空字符串
function fix(num, N) { , N); return Math.round(num * base) / base; } 实例,取小数后边两位 var yhmoney2 = fix(1 ...
- vue简单的导航栏
<style> img{ display:block; margin:0 auto; width:500px; height:500px; } #app li{ list-style: n ...
- 对象的API
entries keys values is assign create toSting ProetydefineProperty(obj,key,propety) Object.entries(), ...
- 16Linxu_Squid_iSCSI
使用Squid部署代理缓存服务 yum install squid 标准正向代理: 透明正向代理 反向代理 ACL访问控制 使用iSCSI服务部署网络存储 yum install targetd ta ...
- MySql TIMEDIFF做计算之后,后台报Illegal hour value '24' for java.sql.Time type 问题
页面需要显示这种格式:31:01:20 但是后台Springboot会提示Illegal hour value '24' for java.sql.Time type in value '24:00: ...