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;
    }
    
  • 相关阅读:
    html 带渐变的吸顶效果 vue
    Linux添加环境变量
    C#集合通论
    Android adb 命令导出数据库
    查看签名方式及签名信息
    啥 啥 啥,服务治理是个啥
    令牌桶、漏斗、冷启动限流在sentinel的应用
    MySQL事务
    MySQL优化
    MySQL视图、存储过程、函数、触发器
  • 原文地址:https://www.cnblogs.com/lokiii/p/8951166.html
Copyright © 2011-2022 走看看