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!
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 mi and ci (1 ≤ mi, ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
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.
3 3 5 2 1 4 2
Mishka
2 6 1 1 6
Friendship is magic!^^
3 1 5 3 3 2 2
Chris
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.
/* ***********************************************
Author : ryc
Created Time : 2016-08-05 Friday
File Name : E:\acm\codeforces\365A.cpp
Language : c++
Copyright 2016 ryc All Rights Reserved
************************************************ */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn=100010;
int num[maxn];
int main()
{
int n,a=0,b=0;
scanf("%d",&n);
for(int i=1;i<=n;++i){
int k1,k2;
scanf("%d%d",&k1,&k2);
if(k1>k2)a++;
else if(k1<k2)b++;
}
if(a==b){
printf("Friendship is magic!^^\n");
}
else if(a>b){
printf("Mishka\n");
}
else if(a<b){
printf("Chris\n");
}
return 0;
}
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:
- XXX consists of n cities, k of whose (just imagine!) are capital cities.
- 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.
- 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.
- 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.
- There is at most one road between any two cities.
- 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 between a and b you are to find sum of products ca·cb. Will you help her?
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.
Print the only integer — summary price of passing each of the roads in XXX.
4 1 2 3 1 2 3
17
5 2 3 5 2 2 4 1 4
71
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.
/* ***********************************************
Author : ryc
Created Time : 2016-08-05 Friday
File Name : E:\acm\codeforces\365B.cpp
Language : c++
Copyright 2016 ryc All Rights Reserved
************************************************ */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<list>
#include<stack>
using namespace std;
const int maxn=100100;
int id[maxn];
long long num[maxn];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
long long sum=0,ans=0;
for(int i=1;i<=n;++i){
scanf("%lld",&num[i]);
sum+=num[i];
}
for(int i=1;i<=k;++i){
scanf("%d",&id[i]);
}
for(int i=1;i<n;++i){
ans=ans+num[i]*num[i+1];
}ans=ans+num[n]*num[1];
long long sum1=0;
for(int i=1;i<=k;++i){
ans=ans+num[id[i]]*sum;
long long x;
if(id[i]==1)x=num[1]*num[2]+num[1]*num[n];
else if(id[i]==n)x=num[n]*num[1]+num[n]*num[n-1];
else {
x=num[id[i]]*num[id[i]+1]+num[id[i]]*num[id[i]-1];
}
ans=ans-x;ans-=num[id[i]]*num[id[i]];ans-=num[id[i]]*sum1;sum1+=num[id[i]];
}
sort(id+1,id+k+1);
for(int i=1;i<k;++i){
if(id[i]==id[i+1]-1)ans+=num[id[i]]*num[id[i+1]];
}
if(id[1]==1&&id[k]==n)ans+=num[1]*num[n];
printf("%lld\n",ans);
return 0;
}
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.
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.
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.
5 5 1 2 1 2 3 1 4 3 3 4 1 4
5.0000000000
Following image describes initial position in the first sample case:
自己把人能否与车相撞这个过程的判断想的太复杂了看了大神的ac代码之后才想明白。
/* ***********************************************
Author : ryc
Created Time : 2016-08-05 Friday
File Name : E:\acm\codeforces\365C.cpp
Language : c++
Copyright 2016 ryc All Rights Reserved
************************************************ */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<map>
#define eps 1e-8
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=10010;
struct point{
double x,y;
}A[maxn],B[5];
int main()
{
int n;
double w,u,v,x,y,maxt,mint;
scanf("%d%lf%lf%lf",&n,&w,&v,&u);
maxt=0,mint=inf;
for(int i=1;i<=n;++i){
scanf("%lf%lf",&x,&y);
double t=x/v-y/u;
maxt=max(maxt,t);
mint=min(mint,t);
}
if(mint>=-eps){//如果有任何一点不能在到来之前通过则不能在汽车到来之前通过
printf("%.6lf\n",w/u);
}
else {//负责只能等待汽车通过之后才能通过路口
printf("%.6lf\n",w/u+maxt);//在整段道路上始终以最快速度走必定是最优的加上等待汽车通过的时间即可。
}
return 0;
}
Little Mishka enjoys programming. Since her birthday has just passed, her friends decided to present her with array of non-negative integers a1, a2, ..., an of n elements!
Mishka loved the array and she instantly decided to determine its beauty value, but she is too little and can't process large arrays. Right because of that she invited you to visit her and asked you to process m queries.
Each query is processed in the following way:
- Two integers l and r (1 ≤ l ≤ r ≤ n) are specified — bounds of query segment.
- Integers, presented in array segment [l, r] (in sequence of integers al, al + 1, ..., ar) even number of times, are written down.
- XOR-sum of written down integers is calculated, and this value is the answer for a query. Formally, if integers written down in point 2 are x1, x2, ..., xk, then Mishka wants to know the value , where — operator of exclusive bitwise OR.
Since only the little bears know the definition of array beauty, all you are to do is to answer each of queries presented.
The first line of the input contains single integer n (1 ≤ n ≤ 1 000 000) — the number of elements in the array.
The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — array elements.
The third line of the input contains single integer m (1 ≤ m ≤ 1 000 000) — the number of queries.
Each of the next m lines describes corresponding query by a pair of integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of query segment.
Print m non-negative integers — the answers for the queries in the order they appear in the input.
3 3 7 8 1 1 3
0
7 1 2 1 3 3 2 3 5 4 7 4 5 1 3 1 7 1 5
0 3 1 3 2
In the second sample:
There is no integers in the segment of the first query, presented even number of times in the segment — the answer is 0.
In the second query there is only integer 3 is presented even number of times — the answer is 3.
In the third query only integer 1 is written down — the answer is 1.
In the fourth query all array elements are considered. Only 1 and 2 are presented there even number of times. The answer is .
In the fifth query 1 and 3 are written down. The answer is .
此题不知道如何将偶数的个数变为奇数奇数变为偶数。看了ac代码之后才明白,佩服啊。。
/* ***********************************************
Author : ryc
Created Time : 2016-08-05 Friday
File Name : E:\acm\codeforces\365D.cpp
Language : c++
Copyright 2016 ryc All Rights Reserved
************************************************ */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<map>
#define eps 1e-8
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1000010;
struct Node{
int l,i;
};
map<long long ,int>vis;
vector<Node>vec[maxn];
long long ans[maxn];
long long pre[maxn];
long long num[maxn],c[maxn];
long long low(int x){
return x&(-x);
}
void add(int p,long long q){
while(p<maxn){
c[p]^=q;
p+=low(p);
}
}
long long sum(int n){
long long value=0;
while(n>0){
value^=c[n];
n-=low(n);
}
return value;
}
int main()
{
int n;cin>>n;
for(int i=1;i<=n;++i){
scanf("%lld",&num[i]);
pre[i]=pre[i-1]^num[i];
}
int m;cin>>m;
for(int i=1;i<=m;++i){
int l,r;
scanf("%d%d",&l,&r);
ans[i]=pre[r]^pre[l-1];//处理出每个区间的异或和
Node u;u.l=l;u.i=i;
vec[r].push_back(u);
}
for(int i=1;i<=n;++i){
if(vis.count(num[i])){
add(vis[num[i]],num[i]);//消去前一个位置的此数
}
vis[num[i]]=i;add(i,num[i]);
long long cnt=sum(i);
for(int j=0;j<vec[i].size();++j){
//当一个数在一个区间内出现偶数次的时候ans中记录的次数的的异或值为0 cnt^(sum(vec[i][j].l-1))就可以记录出这个数
ans[vec[i][j].i]^=cnt^(sum(vec[i][j].l-1));
}
}
for(int i=1;i<=m;++i){
printf("%lld\n",ans[i]);
}
return 0;
}