题目链接:点击打开链接

A. Mishka and Game
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.

Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.

In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.

Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!

Input

The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds.

The next n lines contains rounds description. i-th of them contains pair of integers m and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.

Output

If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.

If Chris is the winner of the game, print "Chris" (without quotes) in the only line.

If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.

Examples
input
3
3 5
2 1
4 2

output
Mishka

input
2
6 1
1 6

output
Friendship is magic!^^

input
3
1 5
3 3
2 2

output
Chris

Note

In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.

In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.

In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.

题意:就是两个人掷色子比大小

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{int n;while(~scanf("%d",&n)){int a,b,win1=0,win2=0;while(n--){scanf("%d %d",&a,&b);if(a>b)    win1++;if(a<b) win2++;}if(win1>win2)  puts("Mishka");if(win1<win2)   puts("Chris");if(win1==win2)    puts("Friendship is magic!^^");}return 0;
}

题目链接:点击打开链接

B. Mishka and trip
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.

Here are some interesting facts about XXX:

  1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
  2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
  3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 — 2 — ... — n — 1. Formally, for every 1 ≤ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
  4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every1 ≤ i ≤ n,  i ≠ x, there is a road between cities x and i.
  5. There is at most one road between any two cities.
  6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ci·cj.

Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road betweena and b you are to find sum of products ca·cb. Will you help her?

Input

The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them.

The second line of the input contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 10 000) — beauty values of the cities.

The third line of the input contains k distinct integers id1, id2, ..., idk (1 ≤ idi ≤ n) — indices of capital cities. Indices are given in ascending order.

Output

Print the only integer — summary price of passing each of the roads in XXX.

Examples

input
4 1
2 3 1 2
3

output
17

input
5 2
3 5 2 2 4
1 4

output
71

Note

This image describes first sample case:

It is easy to see that summary price is equal to 17.

This image describes second sample case:

It is easy to see that summary price is equal to 71.

题意:有n个城市,普通城市会和下一个城市有一条连线,省会城市 会与其他所有城市都有一条边,边的权值是两个城市权值的乘积,求所有边的权值之和!

思路:如第二个样例吧,省会城市有1和4,那么先算1相连的,用分配律计算是:a1*a2 + a1*a3 + a1*a4+a1*a5 = a1*T�n�qO �+a4+a5)所以可以先预处理一个权值之和,第一个城市相连边权值之和就是 (sum - a[1]) * a[1];计算城市4,计算要减去重复的,计算式是 (sum-a[1]-a[4])*a[4]  这就是规律了。这样算完后,会发现城市2还没有访问,所以可以在遍历一遍n个城市,找出未访问的城市,加上它即可

#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
int n,k;
LL id[100010],c[100010],val[100010];
bool vis[100010];
int main()
{while(~scanf("%d %d",&n,&k)){LL sum=0;for(int i=1;i<=n;i++){scanf("%I64d",&c[i]);sum+=c[i];}for(int i=1;i<=k;i++)scanf("%I64d",&id[i]);memset(vis,0,sizeof(vis));LL mark=0,ans=0;for(int i=1;i<=k;i++) // 从首都城市开始计算 {ans+=(sum-c[id[i]]-mark)*c[id[i]];mark+=c[id[i]];vis[id[i]]=1; // 每次标记 首都城市 和 首都城市的前驱城市 vis[id[i]==1?n:(id[i]-1)]=1;}for(int i=1;i<=n;i++){if(vis[i])  continue;ans+=c[i]*c[i==n?1:(i+1)];}printf("%I64d\n",ans);}return 0;
}

题目链接:点击打开链接

C. Chris and Road
time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

And while Mishka is enjoying her trip...

Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.

Once walking with his friend, John gave Chris the following problem:

At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of nvertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.

There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points(0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.

Please look at the sample note picture for better understanding.

We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).

You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.

Input

The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v,  u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.

The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109,0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.

Output

Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.

Example
input
5 5 1 21 23 14 33 41 4

output
5.0000000000

Note

Following image describes initial position in the first sample case:

这题开始以为很麻烦;看了别人的思路恍然大悟

题解:一共有三种情况:

①. 人以最大速度u前进时,汽车的速度很慢,任意一点都到达不了人的位置

②.人以最大速度u前行时,汽车的速度很快,在人达到之前汽车的任意一点都已经通过了y轴

③.人以最大速度u前进时,会与汽车相撞,需要调整速度躲避汽车

上面三种情况,①②两种都可以直接以最大速度u通过马路。对于第③种情况,我们可以在汽车最后一个通过y轴的点通过时行人恰好到达那个点的位置(如上图就是(0,3)),然后全速u走到终点。在过这个点之前,行人怎么变速的,我们就没必要考虑,反正他到达这个点的时间就是汽车完全通过这个点的时间,这样想来就好多了

#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=100010;
int n;
double x[MAX],y[MAX];
int main()
{double w,v,u;while(~scanf("%d %lf %lf %lf",&n,&w,&v,&u)){bool flag1=0,flag2=0;double ans=0;for(int i=0;i<n;i++){scanf("%lf %lf",&x[i],&y[i]);if(x[i]/v<y[i]/u) flag1=1;if(x[i]/v>y[i]/u)   flag2=1;ans=max(ans,x[i]/v+(w-y[i])/u); // 每次更新一下时间,遍历完所有的点 即可 }if(flag1+flag2==2) // 如果两个 flag 都被标记就满足第三种情况 printf("%.10lf\n",ans);elseprintf("%.10lf\n",w/u); // 只有一个点被标记,就是前两种情况 }return 0;
}

codeforces-703(好题)相关推荐

  1. codeforces 1041a(水题)

    http://codeforces.com/problemset/problem/1041/A(题目链接) There was an electronic store heist last night ...

  2. Codeforces科学刷题指南,一图一表便够了

    简要介绍如何科学地刷算法题,来提高自己解决问题的能力,并利用爬虫抓取Codeforces的题库,来分析题目难度以及算法分类的关系 无论做什么事,多尝试.找套路.然后刻意练习都是至关重要的.对信息科学竞 ...

  3. codeforces - 1315C - 思维题

    原题链接:https://codeforces.com/problemset/problem/1315/C 翻译: 这是一个猜谜游戏,你需要猜中一个序列,谜题是一个序列,我们设为b,长度为n.你需要根 ...

  4. codeforces #261 C题 Pashmak and Buses(瞎搞)

    题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...

  5. Codeforces科学刷题指南

    简要介绍如何科学地刷算法题,来提高自己解决问题的能力,并利用爬虫抓取Codeforces的题库,来分析题目难度以及算法分类的关系 无论做什么事,多尝试.找套路.然后刻意练习都是至关重要的.对信息科学竞 ...

  6. codeforces每日5题(均1500)-第十三天

    Case of Matryoshkas 题面翻译 这是一套有n个娃娃的套娃,由1到n依次编号.编号小的娃娃可以放进编号大的娃娃里面,但是不能平行的放入两个娃娃,即套娃在嵌套放置的时候只能一个套一个例如 ...

  7. codeforces 数论分析题

    题目:http://codeforces.com/contest/359/problem/C 题意:给一个素数x和一个长度为n的数列a[],求的分子和分母的最大公约数. 分析:对于分子来说,我们把分子 ...

  8. Minimizing Difference CodeForces - 1244E(贪心题)

    题目 题意 官方题解: 百度翻译 思路 ac代码 题意 给出一列数,至多n个操作使其中的数+1或-1,要求得到最小的差值(最大值-最小值): You are given a sequence a1_{ ...

  9. Codeforces 802 补题

    codeforces802 A-O Helvetic Coding Contest 2017 online mirror  A  Heidi and Library (easy) 水题 同B #inc ...

  10. codeforces每日5题(均1500)-第八天

    Cola 题面翻译 有a瓶0.5升,b瓶1升,c瓶2升的可乐,求买n升可乐的方案数 输入 nnn , aaa , bbb , ccc ( 1<=n<=100001<=n<=10 ...

最新文章

  1. 设计模式之状态模块加观察者模式
  2. Smarty模板的基础
  3. 数据蒋堂 | 做基础软件要投入很多钱?
  4. Crash常见异常总结
  5. python二十三:装饰器 ?
  6. 基于bert模型的文本分类研究:“Predict the Happiness”挑战
  7. jenkins+k8s实现持续集成
  8. spring boot----简单入门
  9. 乘积最大(信息学奥赛一本通-T1275)
  10. 机器学习入门一 ------- 什么是机器学习,机器学习的在实际中的用处
  11. [译] 如何用ps制作泼水字
  12. Hadoop2.2.0 + HBase0.96 伪分布式安装
  13. maven-surefire-plugin常用配置
  14. 计算机更改刷新频率,win10系统更改屏幕刷新频率的设置方案
  15. chrome插件之vimium,解放你的鼠标
  16. html radio vue,Vue.js选中动态绑定的radio的指定项_心病_前端开发者
  17. JavaScript函数式编程入门-计算器应用
  18. 又涨了?2023全国程序员薪资最新统计(文末附招聘岗位)
  19. 报错https://chat.openai.com/ api/auth/ session 429怎么办
  20. 索尼g8441是什么版本_复兴之路!索尼新机G8341/G8441现身波兰

热门文章

  1. 第一天的学习内容----Excel自动化处理
  2. 新浪微博用户兴趣建模系统架构
  3. vbs让电脑发音说话
  4. 前端开发中spa的优缺点_使用单Spa开发和部署微前端
  5. prisma中where对象转换RedisJson查询字符串
  6. linux系统文件夹
  7. 搜索与问答——【NeurIPS 2021】BEIR:信息检索模型零样本评估的异构基准
  8. 在python中使用autoit_Python + Selenium + AutoIt 模拟键盘实现另存为、上传、下载操作详解...
  9. [荐][转]如何用美剧真正提升你的英语水平
  10. AWK awk xxx xxx