题目链接:点击打开链接
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 m 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.
题意:就是两个人掷色子比大小
#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;
}
题目链接:点击打开链接
题意:有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;
}
题目链接:点击打开链接
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:
题解:一共有三种情况:
①. 人以最大速度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);
else
printf("%.10lf\n",w/u); // 只有一个点被标记,就是前两种情况
}
return 0;
}