poj2586 Y2K Accounting Bug(贪心,java)
来源:互联网 发布:广州seo顾问 编辑:程序博客网 时间:2024/05/22 23:09
package test;
import java.util.Scanner;
/**问题请参考http://poj.org/problem?id=2109
* @author rayli
* @date:2014-7-22 下午7:05:17
* 题意 :一个公司在12个月中,或固定盈余s,或固定亏损d.
* 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为亏损),
* 而一年中只有8个连续的5个月,分别为1~5,2~6,…,8~12问全年是否可能盈利?
* 若可能,输出可能最大盈利金额,否则输出“Deficit".
*
* x=1: ssssd,ssssd,ss d>4s 赢利10个月 10s-2d
* x=2: sssdd,sssdd,ss 2d>3s 赢利8个月 8s-4d
* x=3: ssddd,ssddd,ss 3d>2s 赢利6个月 6s-6d
* x=4: sdddd,sdddd,sd 4d>s 赢利3个月 3s-9d
* x=5: ddddd,ddddd,dd 4d<s 无赢利
*/
public class Cryptography
{
int ans;
void greedy(int s, int d)
{
// ans = 0;
if( 4 * s < d)
{
ans = 10 * s - 2 * d;
}
else if(3 * s < 2 * d)
{
ans = 8 * s - 4 * d;
}
else if( 2 * s < 3 * d)
{
ans = 6 * s - 6 * d;
}
else if(s < 4 * d)
{
ans = 3 * s - 9 * d;
}
else
{
ans = -1;
}
}
void output()
{
if(ans < 0)
System.out.println("Deficit");
else
System.out.println(ans);
}
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
Cryptography ct = new Cryptography();
int s;
int d;
while(cin.hasNext())
{
s = cin.nextInt();
d = cin.nextInt();
if(s > 0 && d > 0)
{
ct.greedy(s, d);
ct.output();
}
else
break;
}
cin.close();
}
}
import java.util.Scanner;
/**问题请参考http://poj.org/problem?id=2109
* @author rayli
* @date:2014-7-22 下午7:05:17
* 题意 :一个公司在12个月中,或固定盈余s,或固定亏损d.
* 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为亏损),
* 而一年中只有8个连续的5个月,分别为1~5,2~6,…,8~12问全年是否可能盈利?
* 若可能,输出可能最大盈利金额,否则输出“Deficit".
*
* x=1: ssssd,ssssd,ss d>4s 赢利10个月 10s-2d
* x=2: sssdd,sssdd,ss 2d>3s 赢利8个月 8s-4d
* x=3: ssddd,ssddd,ss 3d>2s 赢利6个月 6s-6d
* x=4: sdddd,sdddd,sd 4d>s 赢利3个月 3s-9d
* x=5: ddddd,ddddd,dd 4d<s 无赢利
*/
public class Cryptography
{
int ans;
void greedy(int s, int d)
{
// ans = 0;
if( 4 * s < d)
{
ans = 10 * s - 2 * d;
}
else if(3 * s < 2 * d)
{
ans = 8 * s - 4 * d;
}
else if( 2 * s < 3 * d)
{
ans = 6 * s - 6 * d;
}
else if(s < 4 * d)
{
ans = 3 * s - 9 * d;
}
else
{
ans = -1;
}
}
void output()
{
if(ans < 0)
System.out.println("Deficit");
else
System.out.println(ans);
}
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
Cryptography ct = new Cryptography();
int s;
int d;
while(cin.hasNext())
{
s = cin.nextInt();
d = cin.nextInt();
if(s > 0 && d > 0)
{
ct.greedy(s, d);
ct.output();
}
else
break;
}
cin.close();
}
}
阅读全文
0 0
- poj2586 Y2K Accounting Bug(贪心,java)
- 【贪心】POJ2586 Y2K Accounting Bug
- poj2586 Y2K Accounting Bug 贪心
- POJ2586 Y2K Accounting Bug(贪心)
- POJ2586 Y2K Accounting Bug 贪心
- poj2586 Y2K Accounting Bug 贪心
- poj2586 Y2K Accounting Bug 贪心
- POJ2586 Y2K Accounting Bug(贪心)
- POJ2586《Y2K Accounting Bug》方法:贪心
- poj2586 Y2K Accounting Bug(贪心)
- POJ2586--Y2K Accounting Bug(贪心)
- POJ2586 Y2K Accounting Bug(贪心)
- Y2K Accounting Bug POJ2586
- poj2586 Y2K Accounting Bug
- POJ2586 Y2K Accounting Bug
- POJ2586 Y2K Accounting Bug
- POJ2586--Y2K Accounting Bug
- poj2586 Y2K Accounting Bug
- 为什么ESP8266 TCP透传过程会丢包?8266流控原理以及如何设置
- poj 3278 Catch That Cow
- poj2965 The Pilots Brothers\' refrigerator
- poj1328 Radar Installation(java)
- poj2109 Power of Cryptography(java)
- poj2586 Y2K Accounting Bug(贪心,java)
- poj 1573 Robot Motion(java 模拟)
- poj 1125 Stockbroker Grapevine
- poj1860 Currency Exchange(java + bellman-Ford)
- poj2485 Highways(prim java)
- poj 3026 Borg Maze(java bfs + prim)
- poj 1258 Agri-Net( java prim)
- poj 1789 Truck History(java + prim)
- poj 1094 Sorting It All Out(java + 拓扑排序)