码迷,mamicode.com
首页 > 其他好文 > 详细

HAOI2014 走出金字塔

时间:2019-03-05 09:20:29      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:+=   一个   end   int   def   node   找规律   printf   http   

题目链接:戳我

找规律。

不过为了方便,每次我们计算入口和某一个出口之间需要花费的体力值的时候,不妨把x较小的假设成塔顶,这样的话另一个就不需要分类讨论了。

详细请看代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define MAXN 1000010
using namespace std;
int n,m,r,s,x,y,xx,yy;
int ans=2147483647,cur_ans;
struct Node{int x,y;}node[MAXN];
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("ce.in","r",stdin);
    #endif
    scanf("%d%d%d%d",&n,&m,&r,&s);
    for(int i=0;i<=m;i++)
        scanf("%d%d",&node[i].x,&node[i].y);
    for(int i=1;i<=n;i++)
    {
        x=node[i].x,y=node[i].y;
        xx=node[0].x,yy=node[0].y;
        cur_ans=0;
        if(x<xx) swap(xx,x),swap(yy,y);
        if(y%2==0) x--,y--,cur_ans++;
        if(yy%2==0) xx--,yy--,cur_ans--;
        x-=xx; y-=yy-1;
        if(y<1) cur_ans+=1-y;
        if(y>(2*(x+1)-1)) cur_ans+=y-2*(x+1)+1;
        cur_ans+=2*x;
        ans=min(ans,cur_ans);
    }
    ans*=r;
    if(ans+1<=s) printf("%d\n",s-ans-1);
    else printf("-1\n");
    return 0;   
}

HAOI2014 走出金字塔

标签:+=   一个   end   int   def   node   找规律   printf   http   

原文地址:https://www.cnblogs.com/fengxunling/p/10462517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!