zoukankan      html  css  js  c++  java
  • Dima and Guards

    Description

    Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...

    There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.

    In order to pass through a guardpost, one needs to bribe both guards.

    The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.

    Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 ≤ a, b, c, d ≤ 105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.

    Output

    In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.

    The guardposts are numbered from 1 to 4 according to the order given in the input.

    If there are multiple solutions, you can print any of them.

    Sample Input

    Input
    10
    5 6 5 6
    6 6 7 7
    5 8 6 6
    9 9 9 9
    
    Output
    1 5 5
    
    Input
    10
    6 6 6 6
    7 7 7 7
    4 4 4 4
    8 8 8 8
    
    Output
    3 4 6
    
    Input
    5
    3 3 3 3
    3 3 3 3
    3 3 3 3
    3 3 3 3
    
    Output
    -1

    Hint

    Explanation of the first example.

    The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.

    Explanation of the second example.

    Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.

    女寝一共四个入口  每个入口有两个阿姨  如果男孩要进去必须要贿赂俩阿姨 

    现在给出男孩手持的钱数和四个入口 每个阿姨了解的市场上巧克力和水果的最低价格

     首先输入男孩的钱数

    接下来每行代表一个入口  输入第一个阿姨了解的市场上巧克力和水果的最低价格  第二个阿姨市场上巧克力和水果的最低价格

    输出入口  和第一个阿姨得到多少钱第二个阿姨得到多少钱(查找出俩阿姨中所需钱数最少的  另一个阿姨应该得到剩下的所有钱)(这里不对是会一直wrong  -.-) 

    进不去输出-1

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<queue>
    #include<algorithm>
    using namespace std;
    int map[5][5];
    int main()
    {
    	int n;
    	scanf("%d",&n);
    	int t=0;
    	int flog=0;
    	int minn=10000;
    	for(int i=1;i<=4;i++)
    	{
        	scanf("%d%d%d%d",&map[i][1],&map[i][2],&map[i][3],&map[i][4]);
    	}
    	int sum1,sum2;
    	for(int i=1;i<=4;i++)
    	{
    	    int min1=min(map[i][1],map[i][2]);
    	    int min2=min(map[i][3],map[i][4]);	
    	    if(min1<min2)
    	    {
    	      int yu=n-min1;
    	    	if(yu>=min2)
    	    	{
    			      t=i;
    	    		sum1=min1;
    	    		sum2=yu;
    	    	     flog=1;
    			}
    		}
    		else
    		{
    		   int yu=n-min2;
    			if(yu>=min1)
    			{
    				t=i;
    				sum1=yu;
    				sum2=min2;
    				flog=1;
    			}
    		}
    		if(flog==1)
    		{
    			break;
    		}
    	}
    	if(flog==0)
    	{
    		printf("-1
    ");
    	}
    	else
    	{
    		   printf("%d %d %d
    ",t,sum1,sum2);
    	}
    	return 0;
    }
    


    编程五分钟,调试两小时...
  • 相关阅读:
    在MPTCP中引入流量监控——bwm-ng的使用说明
    Ubuntu下配置MPTCP
    实现两台MPTCP主机之间的通信——VSFTPD的配置与使用
    Google 辟谣,Android 和 Chrome OS 不合并
    paper-7
    计算机网络方面国际三大顶尖会议
    谷歌物联网操作系统Android Things揭开面纱
    张纯如
    Android binder机制之 5 --(创建binder服务)
    【BZOJ 1491】[NOI2007]社交网络
  • 原文地址:https://www.cnblogs.com/kingjordan/p/12027036.html
Copyright © 2011-2022 走看看