zoukankan      html  css  js  c++  java
  • [haoi2014]走出金字塔

    在探险的过程中,考古学家Dr. Kong 无意地被困在一个金字塔中。金字塔中的每个房间都是三角形。Dr. Kong可以破壁走到相邻的房间去。
    ::点击图片在新窗口中打开::


    例如,如果他目前处于三角形(2,2)房间,那么他可以破壁走到三角形(2,1)、(2,3)或(1,1)房间。但破壁一面墙需要花费K分钟时间,而考古学家Dr. Kong 的体能只能支持他到S分钟。
    好在Dr. Kong手中有这个金字塔地图,他发现金字塔有许多出口,一旦他进入一个有出口的三角形房间,他再用1分钟就可以走出金字塔。
    ::点击图片在新窗口中打开::
    现在,你能否帮助Dr. Kong找到一个走出金字塔花费时间最少的出口?若能,输出Dr. Kong走出金字塔后还剩下的体能时间(应当大于或等于0);若不能,输出-1。

    这题也没什么好说的,主要思路就是找规律.

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<ctime>
    #include<cmath>
    #include<algorithm>
    #include<queue>
    #include<set>
    #include<map>
    #include<iomanip>
    using namespace std;
    #define LL long long
    #define up(i,j,n) for(int i=j;i<=n;i++)
    #define pii pair<int,int>
    #define db double
    #define eps 1e-4
    #define FILE "dealing"
    int read(){
    	int x=0,f=1,ch=getchar();
    	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    	while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0',ch=getchar();}
    	return x*f;
    }
    const LL maxn=22000,inf=10000000000000LL;
    bool cmin(int& a,int b){return a>b?a=b,true:false;}
    int n,m,k,S,flag=0;
    pii s,t,p;
    int main(){
    	freopen(FILE".in","r",stdin);
    	freopen(FILE".out","w",stdout);
    	int Min=inf;
    	n=read(),m=read(),k=read(),S=read();
    	s.first=read(),s.second=read();
    	p=s;
    	up(i,1,m){
    		s=p;
    		int ans=0;
    		t.first=read(),t.second=read();
    		if(s.first>t.first)swap(s,t);
    		int left=s.second,right=(t.first-s.first)*2+s.second;
    		ans+=(t.first-s.first)*2;
    		if(t.second>=left&&t.second<=right){
    			if(t.second%2!=s.second%2)ans--;
    			cmin(Min,ans);
    			continue;
    		}
    		else {
    			ans+=min(abs(t.second-right),abs(t.second-left));
    			cmin(Min,ans);
    			continue;
    		}
    	}
    	LL ans=(LL)Min*k+1;
    	if(ans<=S)cout<<S-ans<<endl;
    	else cout<<-1<<endl;
    	return 0;
    }
    

      

  • 相关阅读:
    metasploit(MSF)对windows的ms17-010漏洞利用
    kali 解决Metasploit拿到shell后显示中文乱码问题
    kali安装搜狗输入法
    Struts2 为Action 的属性注入值&& 处理请求后缀
    Action 名称搜索顺序&Action配置中的各项默认值
    Struts.xml配置中的包介绍
    AJAX 使用XMLHttpRequest对象发送和接受数据
    Unicode 汉字编码
    HTTP 协议 请求头详解
    java Dom 解析 XML 详细解答
  • 原文地址:https://www.cnblogs.com/chadinblog/p/6476037.html
Copyright © 2011-2022 走看看