zoukankan      html  css  js  c++  java
  • bzoj 3709: [PA2014]Bohater【贪心】

    先打能回血的,按消耗从小到大打;
    然后按回血量降序打剩下的(把消耗和回血反着看就是上一种怪,打法一样);
    中间体力小于0就输出无解

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int N=100005;
    int n,t1,t2;
    long long z;
    struct qwe
    {
    	int d,a,id;
    }a[N],b[N];
    bool cmp1(const qwe &a,const qwe &b)
    {
    	return a.d<b.d;
    }
    bool cmp2(const qwe &a,const qwe &b)
    {
    	return a.a>b.a;
    }
    int read()
    {
    	int r=0,f=1;
    	char p=getchar();
    	while(p>'9'||p<'0')
    	{
    		if(p=='-')
    			f=-1;
    		p=getchar();
    	}
    	while(p>='0'&&p<='9')
    	{
    		r=r*10+p-48;
    		p=getchar();
    	}
    	return r*f;
    }
    int main()
    {
    	n=read(),z=read();
    	for(int i=1;i<=n;i++)
    	{
    		int x=read(),y=read();
    		if(x<=y)
    			a[++t1].d=x,a[t1].a=y,a[t1].id=i;
    		else 
    			b[++t2].d=x,b[t2].a=y,b[t2].id=i;
    	}
    	sort(a+1,a+t1+1,cmp1);
    	for(int i=1;i<=t1;i++)
    	{
    		if(z<=a[i].d)
    		{
    			puts("NIE");
    			return 0;
    		}
    		else 
    			z=z-a[i].d+a[i].a;
    	}
    	sort(b+1,b+t2+1,cmp2);
    	for(int i=1;i<=t2;i++)
    	{
    		if(z<=b[i].d)
    		{
    			puts("NIE");
    			return 0;
    		}
    		else 
    			z=z-b[i].d+b[i].a;
    	}
    	puts("TAK");
    	for(int i=1;i<=t1;i++)
    		printf("%d ",a[i].id);
    	for(int i=1;i<=t2;i++)
    		printf("%d ",b[i].id);
    	return 0;
    }
    
  • 相关阅读:
    【布局】483- 推荐 15 种水平垂直居中布局方案
    【Web技术】482- 浏览器将标签转成 DOM 的过程
    int和Integer的区别
    Rendom类
    java注释
    linux
    AI
    重载和重写
    Iterator接口
    集合和数组的区别
  • 原文地址:https://www.cnblogs.com/lokiii/p/8951166.html
Copyright © 2011-2022 走看看