Codeforces Round #365 (Div. 2) A~C

第二次打CF。。第三题偶遇计算几何吓了一跳。。不过还有半分钟交上去A了。。不过分值当然砍了一大截 - -
排名比上次乐观多了。。。
这里写图片描述

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 mi 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<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<iomanip>
#include<ctime>
#include<climits>
#include<cctype>
#include<algorithm>
#define AUTO "%I64d"
using namespace std;
#define smax(x,tmp) x=max((x),(tmp))
#define smin(x,tmp) x=min((x),(tmp))
#define maxx(x1,x2,x3) max(max(x1,x2),x3)
#define minn(x1,x2,x3) min(min(x1,x2),x3)
typedef long long LL;
const char m[]="Mishka";
const char c[]="Chris";
const char e[]="Friendship is magic!^^";
int main()
{
    int n;
    scanf("%d",&n);
    int t1=0,t2=0;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y) t1++;
        if(x<y) t2++;
    }
    if(t1==t2) printf("%s",e);
    if(t1>t2) printf("%s",m);
    if(t1<t2) printf("%s",c);
    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:

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 every 1 ≤ 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?

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


O(n^2)算法必T..
这个比较考细节。。从1~n正着统计的时候有可能前面非省会节点没有计算到,那么如果当前结点是省会就要加上前面所有不是省会的和,再加上后面所有城市的和,也就是说用两个前缀和来维护。。
还有注意最后一个点n的特判!!有可能在前面计算1号节点的时候就已经统计过了。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<iomanip>
#include<ctime>
#include<climits>
#include<cctype>
#include<algorithm>
#define AUTO "%I64d"
using namespace std;
#define smax(x,tmp) x=max((x),(tmp))
#define smin(x,tmp) x=min((x),(tmp))
#define maxx(x1,x2,x3) max(max(x1,x2),x3)
#define minn(x1,x2,x3) min(min(x1,x2),x3)
typedef long long LL;
const int maxn = 100005;
LL a[maxn],s[maxn],c[maxn];
int n,k;
LL ans;
bool cap[maxn];
inline int ad(int x)
{
    if(x<1) x+=n;
    if(x>n) x-=n;
    return x;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf(AUTO,a+i);
        s[i]=s[i-1]+a[i];
    }
    for(int i=1;i<=k;i++)
    {
        int tmp;
        scanf("%d",&tmp);
        cap[tmp]=true;
    }
    if(n==1 || n==2)
    {
        if(n==1) printf("0");
        else printf(AUTO,a[1]*a[2]);
        exit(0);
    }
    for(int i=1;i<=n;i++)
        if(cap[i]) c[i]=c[i-1];
        else c[i]=c[i-1]+a[i];
    for(int i=1;i<n;i++)
        if(!cap[i]) ans += a[ad(i+1)]*a[i];
        else if(i==1) ans += a[i] * (s[n] - s[i]);
             else ans += a[i] * (c[i-2] + s[n] - s[i]);
    if(cap[n]) ans += a[n] * c[n-2];
    else if(!cap[1]) ans += a[n] * a[1];
    printf(AUTO,ans);
    return 0;
}

C. Chris and Road
time limit per test2 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 n vertices. 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 2
1 2
3 1
4 3
3 4
1 4
output
5.0000000000
Note
Following image describes initial position in the first sample case:
这里写图片描述


第一次做计算几何1A。。。。。
首先分两种情况,能在公交车到y轴之前过去和不能过去
第二种情况我看别人有用二分答案的。。
其实只需要贪心就好了啊。。。。
首先将公交♂车的所有点按照第一关键字y值第二关键字x从小到大排序,那么首先与pedestrian接触的必然是前面的点。
另外第二种情况check的时候只用比较大小即可,不需要计算交点坐标什么的。。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<iomanip>
#include<ctime>
#include<climits>
#include<cctype>
#include<algorithm>
#define AUTO "%I64d"
using namespace std;
#define smax(x,tmp) x=max((x),(tmp))
#define smin(x,tmp) x=min((x),(tmp))
#define maxx(x1,x2,x3) max(max(x1,x2),x3)
#define minn(x1,x2,x3) min(min(x1,x2),x3)
typedef double LL;
const LL eps = 1e-8;
int dcmp(LL x)
{
    if(fabs(x)<eps) return 0;
    if(x>0.0) return 1;
    else return -1;
}
const int maxn = 10005;
struct Node
{
    int x,y;
    bool operator < (const Node t) const
    {
        if(y ^ t.y) return y < t.y;
        return x < t.x;
    }
}node[maxn];
int n,w,v,u;
void init()
{
    scanf("%d%d%d%d",&n,&w,&v,&u);
    for(int i=1;i<=n;i++) scanf("%d%d",&node[i].x,&node[i].y);
    sort(node+1,node+n+1);
}
inline bool check()
{
    for(int i=1;i<=n;i++)
        if(dcmp((LL)node[i].x/v - (LL)node[i].y/u) == -1) return false;
    return true;
}
int main()
{
    init();
    if(check())
    {
        printf("%lf",(LL)w/u);
        exit(0);
    }
    LL ans = 0.0;
    LL cur = 0.0;
    for(int i=1;i<=n;i++)
    {
        if(dcmp( (LL)node[i].x/v-ans - ((LL)node[i].y-cur)/u ) == -1)
            ans+=((LL)node[i].y-cur)/u;
        else ans=(LL)node[i].x/v;
        cur=(LL)node[i].y;
    }
    ans += ((LL)w - cur) / u;
    printf("%lf",ans);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值