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, ...
随机推荐
- 纯JS省市区三级联动
代码下载
- java基础之hashmap
Hashmap是一种非常常用的.应用广泛的数据类型,最近研究到相关的内容,就正好复习一下.网上关于hashmap的文章很多,但到底是自己学习的总结,就发出来跟大家一起分享,一起讨论. 1.hashma ...
- wince6.0 开机启动定制的程序
1.prject.bib MediaApp.exe $(_FLATRELEASEDIR)\MediaApp.exe NK H MediaApp.lnk $(_FLATRELEASEDIR)\Media ...
- Visual Studio Ultimate 2013 with Update 4
Visual Studio Ultimate 2013 with Update 4 是一个先进的开发解决方案,各种规模的团队通过它均可设计和创建引人注目的应用程序,使用户兴致勃勃. Visual St ...
- SharePoint 2013 开发——SharePoint Designer 2013工作流
博客地址:http://blog.csdn.net/FoxDave SharePoint Designer 2013为开发者和高级用户提供了两种创建定制工作流的模式: 基于文本的设计器--即我们一直 ...
- 《java作业》
/* 2.编写一个类,该类有一个方法public int f(int a,int b), 该方法返回a和b的最大公约数.然后再编写一个该类的子类, 要求子类重写方法f,而且重写的方法将返回a和b的最小 ...
- 算法----序列和的 top N
Description: 两个长度为 n 的数组 A 和 B, 各从中选出一个元素相加 A[i] + B[j], 求 top n 小的那些和. 思路 1:这样的和总共有 n^2 个, 排序,然后取前 ...
- HTTP、Scoket网络协议浅解
协议:协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则. HTTP协议:超文本传输协议,它允许将超文本标记语言(HTML)文档从web服务器传送到客户端的浏览器.HTTP是一个 ...
- 使用java理解程序逻辑 第三章 选择结构一
if 选择结构: if(条件){ 代码块 //条件成立后要执行的代码.可以是一条语句,也可以是一组语句 } 可以处理单一或组合条件的情况. if-else 选择结构: if(条件){ ...
- C#处理Json文件
JSON(全称为JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集. JSON采用完全独立于语言的文本格式,可以很容易在 ...