acm之旅--湖南大学保研训练赛3

A - Mishka and Game

题目链接:A - Mishka and Game

  • 思路:水题。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int n, a, b;
    cin >> n;
    int counta = 0, countb = 0;
    for(int i=1; i<=n; i++)
    {
        cin >> a >> b;
        if(a>b)      counta++;
        else if(a<b) countb++;
    }
    if(counta>countb) cout << "Mishka" << endl;
    else if(counta<countb) cout << "Chris" << endl;
    else  cout << "Friendship is magic!^^" << endl;
    return 0;
}
B - Mishka and trip

题目链接:B - Mishka and trip
参考博文:cf B. Mishka and trip (数学)

  • 思路:主要思路是先算中心城市的有关道路的魅力值,然后在算普通城市有关且与中心城市无关的道路的魅力值。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int MAX = 100005;
typedef long long LL;
LL c[MAX], id[MAX];
int vis[MAX];//记录是否是中心城市

int main()
{
    int n, k, idx;
    LL sum = 0, ans = 0, sum2 = 0;
    scanf("%d%d", &n, &k);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld", &c[i]);
        sum += c[i];//所有城市的魅力值
    }
    memset(vis, 0, sizeof(vis));
    for(int i=1; i<=k; i++)
    {
        scanf("%lld", &id[i]);
        vis[id[i]] = 1;
    }
    //中心城市有关道路的魅力值
    LL tol = 0;
    for(int i=1; i<=k; i++)
    {
        tol += c[id[i]];
        ans += c[id[i]]*(sum-tol);
    }
    //计算环路(取出与中心城市有关的道路)
    if(!vis[1] && !vis[n]) ans += c[1]*c[n];
    for(int i=1; i<n; i++)
    {
        if(!vis[i]&&!vis[i+1]) ans += c[i]*c[i+1];
    }
    printf("%lld\n", ans);
    return 0;
}
C - Chris and Road

题目链接:C - Chris and Road
参考博文:Codeforces Round #365 (Div. 2) – C. Chris and Road (思路水题)

  • 思路:看到此题,一脸蒙蔽。以为是计算几何,结果是一个思路奇特的模拟题。
    可以枚举车的所有顶点(x,y),求出当人走到(0,y)时,(x,y)顶点走到了距离Y轴还多远,这样把这个距离的最大值和最小值求出来,Max,Min,
    • 如果Min大于0,表示最能撞到人的顶点都在人的右边,那这个车肯定撞不到人,直接就是w/u!
    • 如果Min小于0,并且Max 大于0,那么你必须等车会撞到你的点过去后再走,答案就是Max/v + w/u!
    • 如果Max也小于0,那么说明这个车开的太快了~,你还没走多久,他已经过去了,这时输出w/u!
      比较时精度也是一个卡点。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const double eps = 1e-8;
const int INF = 1<<29;
int main()
{
    int n, w, v, u;
    double x, y;
    cin >> n >> w >> v >> u;
    double Min = INF*1.0, Max = 0.0;
    for(int i=1; i<=n; i++)
    {
        cin >> x >> y;
        double x1 = x-v*y/u;
        if(x1>Max) Max = x1;
        if(x1<Min) Min = x1;
    }
    if(Min>=-eps || Max<=-eps) printf("%.10f\n", w/(u*1.0));
    else      printf("%.10f\n", w/(u*1.0)+Max/v);
    return 0;
}
D - Mishka and Interesting sum

题目链接:D - Mishka and Interesting sum

E - Mishka and Divisors

题目链接:E - Mishka and Divisors

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值