Description

There are some water, milk and wine in your kitchen. Your naughty little sister made some strange drinks by mixing them together, and then adds some sugar! She wants to know whether they taste good, but she doesn't want to try them herself. She needs your help.

Your sister knows that you don't want to drink them either (anyone wants to?), so she gives you a chance to escape: if you can guess the price of a special drink, she gives you freedom. Warning: she loves her special drink so much that you should never under-estimate its cost! That is, you're to find the most expensive possible price of it.

The price of each drink equals to its cost. If the amounts of water, milk, wine and sugar used in the drink are a1, a2, a3 and a4 respectively, and the unit costs of water, milk, wine and sugar are \(c_1, c_2, c_3\) and \(c_4\) respectively, then the drink costs \(a_1c_1 + a_2c_2 + a_3c_3 + a_4c_4\) . To give you some hope to win, she told you the costs of exactly \(n\) ordinary drinks. Furthermore, she promised that the total cost of sugar a4c4 is always a real number in the interval \([L, R]\) , in any drink.

Sadly, you don't know the exact price of anything (you're a programmer, not a housewife!), but you know that water is the cheapest; wine is the most expensive, i.e., \(0 \le c_1 \le c_2 \le c_3\) . Then the best thing you can do is to assume units costs can be any real numbers satisfying this inequality.

Write a program to find the highest possible price of the special drink.

Input

The input contains several test cases. The first line of each test case contains three positive integers \(n, L, R\) \((1 \le n \le 100, 0 \le L \le R \le 100)\) . The next \(n\) lines each contain four non-negative integer \(a_1, a_2, a_3 , p\) \((0 \le a_1,a_2,a_3 \le 100, 0 \le p \le 10000)\) , the amount of water, milk and wine, and the price. The last line of the case contains three integers \(a1, a2, a3 (0 \le a1,a2,a3 \le 100)\) , the drink to be estimated. The last test case is followed by a single zero, which should not be processed.

Output

For each test case, print the case number and the highest possible price to four decimal places. If the input is selfcontradictory, output ``Inconsistent data". If the price can be arbitrarily large, output "Too expensive!".

Sample Input

1 3 5

1 2 3 10

2 4 6

1 2 4

1 1 1 1

1 1 1

1 3 8

0 1 0 17

0 0 1

3 1 2

2 1 3 14

1 5 1 15

7 3 2 21

4 1 6

2 0 2

45 31 53 4087

30 16 1 1251

11 51 34

0

Sample Output

Case 1: 19.0000

Case 2: Inconsistent data

Case 3: Too expensive!

Case 4: 26.2338

Case 5: 3440.3088

其实就是一个线性规划裸题。

首先有\(c_1-c_2\le0,c_2-c_3\le0\)

之后对于第\(i\)条限制,我们可得\(P-R \le a_{i1}c_1+a_{i2}c_2+a_{i3}c3 \le P-L\)。我们可以把他化成两个限制\(a_{i1}c_1+a_{i2}c_2+a_{i3}c3 \le P-L,-a_{i1}c_1-a_{i2}c_2-a_{i3}c3 \le R-P\)。最大化\(a_1c_1+a_2c_2+a_3c_3+R\)。直接上单纯形就行了。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std; #define maxn (210)
#define eps (1e-8)
int cnt,tot,T,N,L,R,idx[maxn],idy[maxn],q[maxn]; double lim[maxn][5]; inline void pivot(int x,int y)
{
swap(idy[x],idx[y]);
double tmp = lim[x][y]; lim[x][y] = 1/lim[x][y];
for (int i = 0;i <= 3;++i) if (y != i) lim[x][i] /= tmp;
cnt = 0; for (int i = 0;i <= 3;++i) if (i != y&&(lim[x][i] > eps||lim[x][i] < -eps)) q[++cnt] = i;
for (int i = 0;i <= tot;++i)
{
if ((x == i)||(lim[i][y] < eps&&lim[i][y] > -eps)) continue;
for (int j = 1;j <= cnt;++j) lim[i][q[j]] -= lim[x][q[j]]*lim[i][y];
lim[i][y] = -lim[i][y] / tmp;
}
} inline bool work()
{
while (true)
{
int x = 0,y = 0;
for (int i = 1;i <= tot;++i) if (lim[i][0] < -eps&&((!x)||(rand()&1))) x = i; if (!x) break;
for (int i = 1;i <= 3;++i) if (lim[x][i] < -eps&&((!y)||(rand()&1))) y = i; if (!y) return puts("Inconsistent data"),false;
pivot(x,y);
}
while (true)
{
int x = 0,y = 0; double mn = 1e60;
for (int i = 1;i <= 3;++i) if (lim[0][i] > eps) { y = i; break; } if (!y) break;
for (int i = 1;i <= tot;++i) if (lim[i][y] > eps&&lim[i][0]/lim[i][y] < mn) mn = lim[i][0]/lim[i][y],x = i; if (!x) return puts("Too expensive!"),false;
pivot(x,y);
}
return true;
} int main()
{
//freopen("1903.in","r",stdin);
//freopen("1903.out","w",stdout);
srand(233);
while (++T)
{
scanf("%d %d %d",&N,&L,&R); if (!N) break;
printf("Case %d: ",T); tot = 0; memset(lim,0,sizeof(lim));
for (int i = 1;i <= N;++i)
{
for (int j = 1;j <= 3;++j) scanf("%lf",lim[tot+1]+j);
scanf("%lf",lim[++tot]+0); lim[tot+1][0] = -lim[tot][0]+R; ++tot; lim[tot-1][0] -= L;
for (int j = 1;j <= 3;++j) lim[tot][j] = -lim[tot-1][j];
}
lim[++tot][1] = 1; lim[tot][2] = -1;
lim[++tot][2] = 1; lim[tot][3] = -1;
for (int i = 1;i <= 3;++i) scanf("%lf",lim[0]+i);
for (int i = 1;i <= 3;++i) idx[i] = i;
for (int i = 1;i <= tot;++i) idy[i] = i+3;
if (work()) printf("%.4lf\n",-lim[0][0]+R);
}
//fclose(stdin); fclose(stdout);
return 0;
}

Hdu 2979 Expensive Drink的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. HDU 5734 Acperience(返虚入浑)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. HDU 1044 Collect More Jewels(BFS+DFS)

    Collect More Jewels Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  4. hdu 1800 (map)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/ ...

  5. hdu 5444 Elven Postman

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Description Elves are very peculia ...

  6. hdu 1301 Jungle Roads 最小生成树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...

  7. HDU 5734 Acperience

    Acperience Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  8. HDU 5734 Acperience (推导)

    Acperience 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DN ...

  9. Hdu 5444 Elven Postman dfs

    Elven Postman Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

随机推荐

  1. Web Services之SOAP学习

    Web Services之SOAP [toc] 什么是SOAP SOAP(Simple Object Access Protocol)简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一 ...

  2. commons-fileupload源码学习心得

    commons-fileupload依赖于commons-io包. commons-fileupload的使用方法: 1.创建一个文件项目工厂类DiskFileItemFactory.       D ...

  3. 深入Windows窗体原理及控件重绘技巧

    之前有学MFC的同学告诉我觉得Windows的控件重绘难以理解,就算重绘成功了还是有些地方不明白,我觉得可能很多人都有这样的问题,在这里我从Windows窗体的最基本原理来讲解,如果你有类似的疑惑希望 ...

  4. WildFly 9.0.2 启用 SSL

    一.最近做个项目是需要在WildFly中启用https,但是由于WildFly的中文文档比较少所以google了一下,先是通过JBOSS的官方文档了解了一下,但是官方文档这块的配置介绍有些不全面.所以 ...

  5. SQL Server 阻止了对组件 'xp_cmdshell' 的 过程'sys.xp_cmdshell' 的访问

    sql server 2005: EXEC sp_configure N'show advanced options', N'1' RECONFIGURE WITH OVERRIDEEXEC sp_c ...

  6. C#下如何用NPlot绘制期货股票K线图(2):读取数据文件让K线图自动更新

    [内容介绍]上一篇介绍了K线图的基本绘制方法,但很不完善,本篇增加了它直接读取数据的功能,这对于金融市场的数据量大且又需要动态刷新功能的实现很重要. [实现方法] 1.需要一个数据文件,这里用的是直接 ...

  7. java新手笔记17 参数

    package com.yfs.javase; public class ParamDemo { public static void main(String[] args) { int a = 3, ...

  8. PAT_1016 部分A+B

    问题描述: 正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA.例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6. 现给定A.DA.B ...

  9. (转)iOS中3种正则表达式的使用与比较

    .利用NSPredicate(谓词)匹配 例如匹配有效邮箱: NSString *email = @“nijino_saki@.com”: NSString *regex = @"[A-Z0 ...

  10. 【ADO.NET】1、简单配置与使用

    1.一些基础的知识点 ExecuteReader(); //返回查询到的数据,一次一行,用于 selectExecuteNonQuery(); //返回影响的行数,用于 delete,insert,u ...