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, ...
随机推荐
- C#遍历窗体所有控件或某类型所有控件
//遍历窗体所有控件, foreach (Control control in this.Controls) { //遍历后的操作... control.Enabled = false; } 遍历某个 ...
- Linux查看实时带宽流量情况
Linux中查看网卡流量工具有iptraf.iftop以及nethogs等,iftop可以用来监控网卡的实时流量(可以指定网段).反向解析IP.显示端口信息等. 安装iftop的命令如下: CentO ...
- ubuntu下的第一个脚本file.sh
1.新建空文档,写入shell命令: #!/bin/sh cd /home/plg ./usb 第一行一定要有,一开始参考网上写的#!/usr/bin/sh,会提示错误 bash: ./file.sh ...
- Highcharts导出gb2312乱码问题
Highcharts是utf-8编码的,其本地的.net导出环境也是utf-8格式的,导致网页如果采用gb2312编码,显示正常,导出就乱码了.这种现象也同样经常出现在ajax的使用过程中. ajax ...
- Linux面试基础题-2
继续我们这面试系列,在这篇文章里我们给出了10个问题.这些问题或者是在以后的文章中出现的问题不一定在面试中会被问到.然而通过这些文章我们呈现出的是一个交互的学习平台,这必将会对你有很大的帮助. 自本系 ...
- Unity游戏数据用Json保存
(一)关于路径 unity有几个关键的路径 (1).Application.dataPath 只读路径,就是工作目录的Assets路径 (2).Application.streamingAssetsP ...
- [微软]technet与msdn
我们搜索一个微软术语,有时定位到technet页面,有时定位到msdn页面.我直观的理解就是technet教人们如何使用微软产品,而msdn指导人们如何开发基于微软产品的软件.那么微软对它们具体定位是 ...
- iOS开发中关于nslog的几种流行做法小结
不管哪种方法,都必须在PCH文件中做下宏定义 DEBUG和RELEASE要分开,RELEASE时log打印要取消 方法一:简单直接,用几行代码搞定,简洁但功能少 #ifdef DEBUG #defin ...
- InterruptedException 线程异常
InterruptedException 这个异常一般发生在线程中,当一个正在执行的线程被中断时就会出现这个异常-! 简单的说就是:假如有两个线程,第一个线程正在运行,第二个没有运行,这时第二个线程启 ...
- JAVA判断当前时间是上午am还是下午pm
//结果为"0"是上午 结果为"1"是下午 public class GregorianTest { public static void main(Strin ...