UVa12696 - Cabin Baggage(水题)

来源:互联网 发布:二手域名交易平台 编辑:程序博客网 时间:2024/05/19 21:43

Cabin baggage (also called carry on or hand baggage) is a bag that a passenger is allowed to bring
into an aircraft. For safety purpose, cabin baggage must not be too heavy or too big. Every airline
company can set its own size and weight limits of cabin baggage according to the IATA (International
Air Transport Association) guidelines.
ICPC airline has set the cabin baggage limits as follows:
Cabin baggage should have a maximum length of 56 cm, width of 45 cm and depth of 25
cm or the sum of all 3 sides (length+width+depth) should not exceed 125 cm. Its weight
must not exceed 7 kg.
The company has a laser measurement device with high precision to evaluate the size and weight of
cabin baggage. The device gives 4 values which are positive numbers with 2 decimal points. They are
length, width, depth (in cm) and weight (in kg), respectively.
For example,
51.23 40.12 21.20 3.45 (this bag is allowed)
60.00 30.00 20.00 7.00 (this bag is allowed)
52.03 41.25 23.50 7.01 (this bag is not allowed)
You task is to write a program to check whether or not a cabin baggage is allowed.
Input
The rst line contains an integer t (1  t  300) which determines the number of test cases (i.e. cabin
baggage to verify). The following t lines contain the measurement of cabin baggage. Each line contains
4 values which are length, width, depth and weight, respectively. All these 4 values are positive numbers
with 2 decimal points.
Output
For each test case, print out in a line, 1 if it is allowed or 0 otherwise. Finally, print out the total
number of the allowed bags in the last line.
Sample Input
4
51.23 40.12 21.20 3.45
60.00 30.00 20.00 7.00
52.03 41.25 23.50 7.01
50.00 45.00 30.10 6.02
Sample Output
1
1
0
0
2

注意:长度不超过65cm、宽度不超过45、深度不超过25或者三者之和不超过125

import java.io.FileInputStream;import java.io.BufferedInputStream;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.util.Scanner;public class Main implements Runnable{private static final boolean DEBUG = false;private static final double LENGTH = 56, WIDTH = 45, DEPTH = 25, SUM = 125, WEIGHT = 7;private static final double EPS = 1e-6;private PrintWriter cout;private Scanner cin;private double length, width, depth, weight;private void init(){try {if (DEBUG) {cin = new Scanner(new BufferedInputStream(new FileInputStream("d:\\OJ\\uva_in.txt")));} else {cin = new Scanner(new BufferedInputStream(System.in));}cout = new PrintWriter(new OutputStreamWriter(System.out));} catch (Exception e) {e.printStackTrace();}}private void input(){length = cin.nextDouble();width = cin.nextDouble();depth = cin.nextDouble();weight = cin.nextDouble();}private boolean solve(){if (length > LENGTH + EPS && length + width + depth > SUM + EPS) {return false;}if (width > WIDTH + EPS && length + width + depth > SUM + EPS) {return false;}if (depth > DEPTH + EPS && length + width + depth > SUM + EPS) {return false;}if (weight > WEIGHT + EPS) {return false;}return true;}public void run(){init();int t = cin.nextInt();int ans = 0;while (t-- > 0) {input();if (solve()) {cout.println("1");ans++;} else {cout.println("0");}}cout.println(ans);cout.flush();}public static void main(String[] args){new Thread(new Main()).start();}}


0 0
原创粉丝点击