Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑
1 second
256 megabytes
standard input
standard output
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contest started and Vasya submitted the problem d minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs p points tminutes after the contest started, you get points.
Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.
The first line contains four integers a, b, c, d (250 ≤ a, b ≤ 3500, 0 ≤ c, d ≤ 180).
It is guaranteed that numbers a and b are divisible by 250 (just like on any real Codeforces round).
Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points.
500 1000 20 30
Vasya
1000 1000 1 1
Tie
1500 1000 176 177
Misha
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
int m1=max(*a/,a-(a*c)/);
int m2=max(*b/,b-(b*d)/);
if(m1>m2)
printf("Misha\n");
else if(m1==m2)
printf("Tie\n");
else
printf("Vasya\n");
return ;
}
1 second
256 megabytes
standard input
standard output
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.
Next q lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handlenew is not used and has not been used by anyone.
In the first line output the integer n — the number of users that changed their handles at least once.
In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old andnew, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov
3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123
思路:map模拟下就好;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=4e6+,inf=1e9+;
string a[N];
string b[N];
map<string,string>m;
int main()
{
int x;
scanf("%d",&x);
for(int i=;i<=x;i++)
cin>>a[i]>>b[i];
for(int i=x;i>=;i--)
{
m[a[i]]=b[i];
while(m[b[i]]!="")
{
m[a[i]]=m[b[i]];
m[b[i]]="";
}
}
int ans=;
for(int i=;i<=x;i++)
if(m[a[i]]!="")
ans++;
cout<<ans<<endl;
for(int i=;i<=x;i++)
if(m[a[i]]!="")
cout<<a[i]<<" "<<m[a[i]]<<endl;
return ;
}
1 second
256 megabytes
standard input
standard output
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v (if there were no adjacent vertices, he wrote down 0).
Next day Misha couldn't remember what graph he initially had. Misha has values degreev and sv left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.
The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph.
The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.
In the first line print number m, the number of edges of the graph.
Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b).
Edges can be printed in any order; vertices of the edge can also be printed in any order.
3
2 3
1 0
1 0
2
1 0
2 0
2
1 1
1 0
1
0 1
The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
思路:总是有度数为1的节点,裸拓扑;
坑点,多个联通块;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
vector<int>v[N];
int du[N];
int sum[N];
priority_queue<int>q;
int main()
{
int n;
ll ans=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&du[i],&sum[i]);
ans+=du[i];
if(du[i]==)
q.push(i);
}
while(!q.empty())
{
int x=q.top();
q.pop();
if(du[x]==)
continue;
du[x]--;
v[x].push_back(sum[x]);
du[sum[x]]--;
sum[sum[x]]^=x;
if(du[sum[x]]==)
q.push(sum[x]);
}
printf("%lld\n",ans/);
for(int i=;i<n;i++)
{
for(int t=;t<v[i].size();t++)
printf("%d %d\n",i,v[i][t]);
}
return ;
}
/*
4
1 1
1 0
1 3
1 2
*/
Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑的更多相关文章
- Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #285 (Div. 2)C. Misha and Forest(拓扑排序)
传送门 Description Let's define a forest as a non-directed acyclic graph (also without loops and parall ...
- 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...
- 字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles
题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上 ...
- 水题 Codeforces Round #285 (Div. 2) C. Misha and Forest
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #285 (Div.1 B & Div.2 D) Misha and Permutations Summation --二分+树状数组
题意:给出两个排列,求出每个排列在全排列的排行,相加,模上n!(全排列个数)得出一个数k,求出排行为k的排列. 解法:首先要得出定位方法,即知道某个排列是第几个排列.比如 (0, 1, 2), (0, ...
随机推荐
- (六)通过solr7的API实现商品的列表查询
(六)通过solr7的API实现商品的列表查询 工具类: 获取 HttpSolrClient public class Constant { public static HttpSolrClient ...
- MYSQL存储引擎介绍--应用场景
MySQL存储引擎通常有哪3种?各自分别有什么特点?应用场景是哪些? MySQL5.5以后默认使用InnoDB存储引擎,其中InnoDB和BDB提供事务安全表,其它存储引擎都是非事务安全表.若要修改默 ...
- 在使用NavigationController情况下的布局的Y轴的起始位置
在有的时候,当一个ViewController被push进一个NavigationController的时候,view上会有一个高度为64的NavigationBar(除非主动隐藏了Navigatio ...
- C++常备知识总结
1.extern表示是外部函数或外部变量,比如: 1.extern void add(int x,inty);表示该函数主体不在当前模块中,在另一个模块中(文件)2.extern int total; ...
- jquery.fileDownload plugin: Success msg alert before actual pdf download completed
Currently , I use jquery fileDownload plugin to download multiple pdf that in a list page, which eve ...
- 洛谷 P4071 [SDOI2016]排列计数
洛谷 这是一道组合数学题. 对于一个长为n的序列,首先我们要选m个使之稳定\(C^{m}_{n}\). 且要保证剩下的序列不稳定,即错排\(D_{n-m}\). 所以答案就是:\[ANS=C^{m}_ ...
- mac开发环境爬坑记(搭建php+nginx+mysql+redis+laravel+git+phpstorm)
题外话:前几天,终于以原价一半的价格,将我那台15版mbp在bbs上卖了出去.之所以用了“终于”这个词儿,是我一直迟迟没有下定决心卖掉它,可眼瞅着再不卖掉,又要掉价,况且我的新电脑,也终于下来了. 话 ...
- python多进程编程(二)
进程同步(锁) 进程之间数据不共享,但是共享同一套文件系统,所以访问同一个文件,或同一个打印终端,是没有问题的, 而共享带来的是竞争,竞争带来的结果就是错乱,如何控制,就是加锁处理 part1:多个进 ...
- make编译四
书写命令 每条规则中的命令和操作系统 Shell 的命令行是一致的. make 会按顺序一条一条的执行命令, 每条命令的开头必须以[Tab]键开头, 除非,命令是紧跟在依赖规则后面的分号后的.在命令行 ...
- 使用Kotlin开发Android应用(III):扩展函数和默认值
通过前面两篇文章,我们学习了Kotlin的基本知识,并知道如何配置工程,本文将接着介绍Java没有的而Kotlin实现了的有趣的特性.记住当你对Kotlin语言有任何疑问时,请参考官方指南.该指南组织 ...