If you are not understand problem: when print undefined and when error, try to brute force it:) p n p=0 and n=0 undefined p=0 and n!=0 error p!=0 and n=0 error v (p=0 error, n=0 undefined, vg<=0 error) t (n=0 error, p=0 undefined, tg<=0 error) #include <iostream> #include <string> #include <algorithm> #include <vector> #include <stdio.h> #include <cmath> using namespace std; int p=0,n=0,V=0,T=0; char c; int a=0,b=0,c1=0,d=0; double R=8.314; int main() { for(int i = 0; i < 3; i++) { cin >> c; if(c=='p') { cin >> c; cin >> p; a++; } if(c=='n') { cin >> c; cin >> n; b++; } if(c=='V') { cin >> c; cin >> V; c1++; } if(c=='T') { cin >> c; cin >> T; d++; } } if(a==0) cout << "p = " << R*n*T/V; if(b==0) cout << "n = " << p*V/(R*T); if(c1==0) { if(p==0 && n==0) { cout << "undefined"; return 0; } if(p==0 || n==0) { cout << "error"; return 0; } cout << "V = " << R*n*T/p; } if(d==0) { if(p==0 && n==0) { cout << "undefined"; return 0; } if(p==0 || n==0) { cout << "error"; return 0; } cout << "T = " << p*V/(R*n); } return 0; } Так же было и на самом контесте WA 11, сейчас тоже WA 11, хотя на разборе говорили все тоже самое Edited by author 20.03.2011 13:07 Edited by author 20.03.2011 13:07 Use printf; Write something like this printf("n = %0.7Lf",rez); and be sure that you don't have any cout<<. I don't know the reason, this was my "mistake" and produced many WA :( Edited by author 14.07.2011 17:56 You can also write with setprecision. I think you have to output at least 3 decimals but I'm not sure. You must use fixed setprecision at least with 5 decimals: cout << fixed << setprecision(5); in 12 test answer is p = 0. I write in my code "0" instead of "p = 0" and have WA12. Good Luck! double res = (bpi*bvi)/(bti*R); cout << "n = "; if(res < 1) printf("%.0f", res); else printf("%.6f", res); When res (n) < 1 u should cout 0 else u should cout number with an error. Good Luck! Can anyone help me with test 4? #include <iostream> #include <cstdio> using namespace std; int main() { char c[3]; float v[3]; float R = 8.314, p, V, T, n; scanf("%c = %f\n", &c[0], &v[0]); scanf("%c = %f\n", &c[1], &v[1]); scanf("%c = %f", &c[2], &v[2]); for(int i = 0; i < 3; i++) { if(c[i] == 'p') p = v[i]; else if(c[i] == 'V') V = v[i]; else if(c[i] == 'T') T = v[i]; else if(c[i] == 'n') n = v[i]; } if(c[0] != 'n' && c[1] != 'n' && c[2] != 'n') { n = p*V/(R*T); if(T == 0 && (p == 0 || V == 0)) cout << "undefined\n"; else if(T == 0 && (p != 0 || V != 0)) cout << "error\n"; else if(p < 0 || V < 0 || T < 0 || n < 0) cout << "error\n"; else printf("n = %f\n", n); } else if(c[0] != 'T' && c[1] != 'T' && c[2] != 'T') { T = p*V/(R*n); if(n == 0 && (p == 0 || V == 0)) cout << "undefined\n"; else if(n == 0 && (p != 0 || V != 0)) cout << "error\n"; else if(p < 0 || V < 0 || n < 0 || T < 0) cout << "error\n"; else printf("T = %f\n", T); } else if(c[0] != 'V' && c[1] != 'V' && c[2] != 'V') { V = n*T*R/p; if(p == 0 && (T == 0 || n == 0)) cout << "undefined\n"; else if(p == 0 && (T != 0 || n != 0)) cout << "error\n"; else if(p < 0 || T < 0 || n < 0 || V < 0) cout << "error\n"; else printf("V = %f\n", V); } else if(c[0] != 'p' && c[1] != 'p' && c[2] != 'p') { p = n*T*R/V; if(T == 0 && (n == 0 || V == 0)) cout << "undefined\n"; else if(T == 0 && (n != 0 || V != 0)) cout << "error\n"; else if(V < 0 || n < 0 || T < 0) cout << "error\n"; else printf("p = %f\n", p); } return 0; } No prob, i proceed to AC now. I guess, Test 6 is: T != 0.0 V != 0.0 p == 0.0 n - ? Ans: n = 0 (just 0, not 0.000000) T != 0.0 V != 0.0 n == 0.0 p - ? Ans: same here, p = 0 your answer is wrong . because it becomes T != 0 and V != 0 and n == 0 answer is error! i think answer is "error" when n != 0 and p == 0 or p != 0 and n == 0 ... What is test 6? I am stuck at it for a very long time! if ((p = 0) and (n = 0)) and ((Pc = 1) and (Nc = 1)) then writeln('undefined'); if (((p = 0) and (n <> 0)) or ((p <> 0) and (n = 0)))and ((Pc = 1) and (Nc = 1)) then writeln('error'); this pair if we have on input n and p (Nc = 1 and Pc = 1) but still i have wa on 6 test! are there any conditions for "error" and "undefined"??? please help. i've already sent my solution for 13 times! and still it's wa... Oh, I have the same problem:( Hi. I find out that test #3 looks like this : p = 3 V = 4 n = 0 When we need to find T, answer will be "undefined" if and only if n = 0 (because, in this way, we get division by zero). In second and in third tests n=0, and we need to find T. I wrote code like this : if( we need find T ) { if( n==0 ) printf("undefined\n"); } But, in this way, I get WA 3. What is wrong? Please, check test, or, if I made mistake, help me figure it out. Thanks. Edited by author 16.07.2012 01:48 the answer is "error" because there is no solution Edited by author 21.08.2012 15:16 But in this case I get WA 2, changing only one string in my code. When n = 0, if we have to calculate T, is the answer 'undefined' ? if we have to calculate V, is the answer 'error' or 'undefined'? Accepted. Formula should be understood like math :) Edited by author 19.03.2011 19:58 Edited by author 19.03.2011 19:58 I don't understend what to do in this case. If we have any of t,v,n,p given to us <= 0 then we should write 'error'? Or I haven't understood the problem right? I just haven't read properly. If we have input p = 0 and n = 0 then we should output 'undefined'. If (p = 0 and n <> 0) or (p <> 0 and n = 0) then we should output 'error'. When we calculate n and p CAN be 0. We just must output '0'. When we calculate T and V CAN'T be 0. We just must output 'error'. I hope it'll help and you will not be sitting for hours as I did. Sorry for my English, but I think it is possible to understand what I meant even with my mistakes. if n or p or T or V not integer then error or some value? Edited by author 15.01.2012 05:32 error if : ( IsUsed[1] && V == 0 ) || ( IsUsed[3] && T == 0 ) || ( IsUsed[0] && IsUsed[2] && p*n==0 && ( p!=0 || n!=0 ) ) undefined if: ( IsUsed[0] && IsUsed[2] && p==0 && n==0 ) It's so hard! =) Print "p = ", but not "P = " And "n = ", but not "N = " import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class T_1823 { public static final double R = 8.314;
public static void main(String[] args) { Scanner in = new Scanner(System.in); Map<Character, Double> mp = new HashMap<Character, Double>(); for (int i = 1; i <=3; i++) { String s = in.nextLine().trim(); mp.put(s.charAt(0), (double)Integer.parseInt(s.charAt(4)+"")); } if(mp.get('T')!=null) { if(mp.get('T')==0) { System.out.println("error"); return; } } if(mp.get('V')!=null) { if(mp.get('V')==0) { System.out.println("error"); return; } } //System.out.println(mp); if(!mp.containsKey('p')) { double p = mp.get('n')*mp.get('T')*R/mp.get('V'); System.out.print("p = "); if(p==0) System.out.println(0); else System.out.printf("%.6f",p); } if(!mp.containsKey('n')) { double n = mp.get('p')*mp.get('V')/R*mp.get('T'); System.out.print("n = "); if(n==0) System.out.print(0); else System.out.printf("%.6f",n); } if(!mp.containsKey('T')) { if(mp.get('n')==0 && mp.get('p')!=0) { System.out.println("error"); } else { if(mp.get('n')==0 && mp.get('p')==0) { System.out.println("undefined"); } else { double T = mp.get('p')*mp.get('V')/R*mp.get('n'); if(T==0) { System.out.println("error"); } else { System.out.print("T = "); System.out.printf("%.6f",T); } } } } if(!mp.containsKey('V')) { if(mp.get('p')==0 && mp.get('n')!=0) { System.out.println("error"); } else { if(mp.get('n')==0 && mp.get('p')==0) { System.out.println("undefined"); } else { double V = mp.get('n')*R*mp.get('T')/mp.get('p'); if(V==0) { System.out.println("error"); } else { System.out.print("V = "); System.out.printf("%.6f",V); } } } } } } Help ! What is test case #2 ? Test 2: n=0 && p=0 should output: "undefined" V or T is calculated to be 0 => output error Please give test. (I already use printf instead of cout <<) Edited by author 29.06.2011 21:58 Edited by author 29.06.2011 21:58 I have found a mistake with computing p. Now AC. p = 1 t = 0 v = 1 i have AC but WA on this test "...It is guaranteed that the temperature and volume are positive..." (c) What is test 3? Can't find any mistakes, but WA#3. p=0 and n!=0 or otherwise |
|