Codeforces Round #485 (Div. 2)重点:D - Fair多源最短路
链接
A - Infinity Gauntlet
map
int n;
int a[N];
int main(){
map<string,int>mp;
string a[8];
mp["purple"] = 1;
a[1] = "Power";
mp["green"] = 2;
a[2] = "Time";
mp["blue"] = 3;
a[3] = "Space";
mp["orange"] = 4;
a[4] = "Soul";
mp["red"] = 5;
a[5] = "Reality";
mp["yellow"] = 6;
a[6] = "Mind";
string b;
while(~scanf("%d" , &n)){
int vis[10];
memset(vis,0,sizeof vis);
for(int i = 1; i <= n ; i ++){
cin >> b;
vis[mp[b]] = 1;
}
vector<string>v;int m = 0;
for(int i = 1; i <= 6; i ++)
if(!vis[i])
m ++ , v.pb(a[i]);
cout << m <<"\n";
for(auto x : v)cout<<x<<"\n";
}
}
B - High School: Become Human
好像是直接判断就可,校内大神说需要取fabs判断更准确附上吧
int main(){
int a,b;
while(~scanf("%d %d" , &a , &b)){
double x = a*1.0,y = b*1.0;
if(y * log(x) < x * log(y)){
puts("<");
}
else if(y * log(x) > x * log(y)){
puts(">");
}
else{
puts("=");
}
}
}
int n,m,t,q;
const double eps=1e-10;
int main(){
int x,y;
double a,b;
scanf("%d%d",&x,&y);
a=log(x)*y;
b=log(y)*x;
if(fabs(a-b)<=eps)printf("=\n");
else if(a-b<0)printf("<\n");
else printf(">\n");
return 0;
}
C - Three displays
枚举中间点
int n ,a[N],b[N];
int main(){
while(~scanf("%d", &n)){
for(int i = 1; i <= n ; i ++){
scanf("%d" ,&a[i]);
}
LL mini = inf;
for(int i =1; i <= n ; i ++){
scanf("%d" ,&b[i]);
}
for(int i = 1; i <= n ; i ++){
int mini1 = 0x3f3f3f3f;
int mini2 = 0x3f3f3f3f;
for(int j = i-1; j >= 1; j --){
if(a[j] < a[i]){
mini1 = min(b[j] , mini1);
}
}
for(int j = i + 1; j <= n ; j ++){
if(a[j] > a[i]){
mini2 = min(b[j] , mini2);
}
}
if(mini1 == 0x3f3f3f3f || mini2 == 0x3f3f3f3f);
else{
mini = min(b[i] + (LL)mini1 + mini2 , mini);
}
}
if(mini == inf)puts("-1");
else{
cout << mini << endl;
}
}
}
D - Fair
多源最短路问题,主要是要想到每种商品到各个节点的最近距离,维护一下就ok
vector<int> G[maxn];
int d[maxn][105];
int n, m, k, s;
int a[maxn];
int vis[maxn];
int num[maxn];
struct node{
int v;
int cnt;
};
int bfs(int cur){
memset(vis, -1, sizeof(vis));
queue<int> q;
for(int i=1; i<=n; i++){
if(a[i] == cur){
q.push(i);
vis[i] = 0;
}
}
while(!q.empty()){
int p = q.front();
q.pop();
for(int i=0; i<G[p].size(); i++){
int temp = G[p][i];
if(vis[temp] == -1){
vis[temp] = vis[p]+1;
q.push(temp);
}
}
}
for(int i=1; i<=n; i++){
d[i][cur] = vis[i];
}
}
int main(){
memset(d, INF, sizeof(d));
scanf("%d%d%d%d", &n, &m, &k, &s);
for(int i=1; i<=n; i++){
scanf("%d", &a[i]);
d[i][a[i]] = 0;
}
int v, u;
for(int i=1; i<=m; i++){
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
for(int i=1; i<=k; i++){
bfs(i);
}
for(int i=1; i<=n; i++){
sort(d[i]+1, d[i]+k+1);
int ans = 0;
for(int j=1; j<=s; j++){
ans += d[i][j];
}
printf("%d ",ans);
}
}
E - Petr and Permutations
模拟水题
int n ;
int a[N];
int pos[N];
int main(){
while(~scanf("%d" , &n)){
for(int i = 1; i <= n ; i ++){
scanf("%d" , &a[i]);
pos[a[i]] = i;
}
int ans = 0;
for(int i = 1; i <= n ; i ++){
if(pos[i] == i)continue;
int x = pos[i];
swap(pos[i],pos[a[i]]);
swap(a[x],a[i]);
ans ++;
}
if((3*n - ans) % 2 == 0){
puts("Petr");
}
else{
puts("Um_nik");
}
}
return 0;
}