Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
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 t minutes 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 题意:根据公式计算得分 输出得分较高的 相同时输出Tie
题解:水
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
#define N 1000000000
using namespace std;
int a,b,c,d;
int main()
{
scanf("%d %d %d %d",&a,&b,&c,&d);
int s1=max(a/*,a-a/*c);
int s2=max(b/*,b-b/*d);
if(s1==s2)
{
cout<<"Tie"<<endl;
}
else
{
if(s1>s2)
{
cout<<"Misha"<<endl;
}
else
cout<<"Vasya"<<endl;
}
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 handle newis 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
题意:给你q个更改 (old,new) 输出所有的通过传递后的最后的更改结果(old,new)
题解:stl的应用 注意细节
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
#define N 1000000000
using namespace std;
map<int ,string> mp1;
map<string,int> mp2;
map<string,string> mp3;
map<string,string> mp4;
string str1,str2;
int n;
int main()
{
scanf("%d",&n);
int jishu=;
for(int i=;i<=n;i++)
{
cin>>str1>>str2;
if(mp2[str1]==)
{
mp1[jishu++]=str1;
mp2[str1]=;
mp2[str2]=;
mp3[str1]=str2;
mp4[str2]=str1;
}
else
{
mp3[mp4[str1]]=str2;
mp4[str2]=mp4[str1];
mp2[str1]=;
mp2[str2]=;
}
}
printf("%d\n",jishu);
for(int i=;i<jishu;i++)
cout<<mp1[i]<<" "<<mp3[mp1[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".
题意:给你n个点 每个点有两个值 num个点与当前点相连 相连的点的序号的异或和为sum 要求输出所有的边 u-v
题解:将所有的num值为1的点入队 不断的出队更新 标记已经入队的点
(存在那种对 已经在队列中的点 的更新) 标记处理
数据
2
1 0
1 1
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
using namespace std;
struct node
{
int pos;
int num;
int sum;
/*friend bool operator < (node aa,node bb)
{
return aa.num<bb.num;
}
*/
} N[];
struct ans
{
int x,y;
} NN[];
queue<node> p;
int n,vis[];
int main()
{
scanf("%d",&n);
for(int i=; i<n; i++)
{
N[i].pos=i;
scanf("%d %d",&N[i].num,&N[i].sum);
if(N[i].num==)
p.push(N[i]);
}
int jishu=;
while(!p.empty())
{
node exm=p.front();
p.pop();
if(exm.num == || vis[exm.pos]) continue; NN[++jishu].x=exm.sum;
NN[jishu].y=exm.pos; N[exm.sum].num--;
if(N[exm.sum].num == ) vis[exm.sum] = ;
N[exm.sum].sum^=exm.pos; if(N[exm.sum].num==)
p.push(N[exm.sum]);
}
printf("%d\n",jishu);
for(int i=; i<=jishu; i++)
printf("%d %d\n",NN[i].x,NN[i].y);
return ;
}
Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序的更多相关文章
- 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) A, B , C 水, map ,拓扑
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)
D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: = 的情况我们用并查集把他们扔到一个集合,然后根据 > ...
- 图论/位运算 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 #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #285 (Div.1 B & Div.2 D) Misha and Permutations Summation --二分+树状数组
题意:给出两个排列,求出每个排列在全排列的排行,相加,模上n!(全排列个数)得出一个数k,求出排行为k的排列. 解法:首先要得出定位方法,即知道某个排列是第几个排列.比如 (0, 1, 2), (0, ...
随机推荐
- NOIP2010解题报告
今天状态不错..1个小时AC了前3题,第四题第一次也拿到了80%的分数,后来换了算法才拿到全部分数.. 第一题: 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 这个翻译软件的原 ...
- 安装arbotix simulator仿真环境()
先安装rbx1功能包: cd ~/catkin_ws/src git clone https://github.com/pirobot/rbx1.git cd rbx1 git checkout in ...
- 仿淘宝js图片切换
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- convert2Mp4 code snippet
#pragma mark - helper - (NSURL *)convert2Mp4:(NSURL *)movUrl { NSURL *mp4Url = nil; AVURLAsset *avAs ...
- 长理ACM 13-围圈报数(谌海军)
题目标题:围圈报数(谌海军) 题目描述:有n(n<=100)围成一圈,顺序排号(从1排到n).从第一个人开始报数(从1报到m(m<=9)),凡报到m的人退出圈子,问最后留下的是原来第几号的 ...
- win7 web开发遇到的问题-由于权限不足而无法读取配置文件,无法访问请求的页面
错误一: HTTP Error 500.19 - Internal Server Error配置错误: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默认设置的 (ov ...
- Portlet和servlet的区别
相同之处 l 都是java技术开发的web组件 l 都是由特定的容器在管理 l 都可以动态产生各种内容 l 生命周期都是由容器管理 l 和客户端的交互通过request/response机制 不同之处 ...
- SharePoint 2013 开发——APP开发的考虑和建议
博客地址:http://blog.csdn.net/FoxDave 需要考虑的方面: 1. 记得CSOM授予网站集及以下的权限,而场解决方案需要整个场的访问权限. 2. 由于应用程序是彼此完全独立 ...
- (转)IOS之Info.plist文件简介
原文:IOS之Info.plist文件简介 http://www.apkbus.com/android-130240-1-1.html (出处: Android开发论坛 - 安卓开发论坛 - Andr ...
- SVG 2D入门9 - 蒙板
SVG支持的蒙板 SVG支持多种蒙板特效,使用这些特性,我们可以做出很多很炫的效果.至于中文中把mask叫做"蒙板"还是"遮罩"就不去区分了,这里都叫做蒙板吧. ...