This is my solution. I have WA at 7-th test. Why? var i,n,hu,sa:integer; a:array[1..100]of integer; b:array[1..100]of string; begin read(n); hu:=3; sa:=10; for i:=1 to n do begin read(a[i]);read(b[i]); if b[i]=' hungry' then if a[i]>hu then hu:=a[i] else hu:=hu else if a[i]<sa then sa:=a[i] else sa:=sa; end; if hu<sa then writeln(sa) else writeln('Inconsistent'); end. Edited by author 23.02.2010 00:54 "Inconsistent" Thanks, but now I've got WA on 7-th test=(( Test: 1 3 satisfied Answer: 3 Why? russian: если по условию он минум от 3 остается голодным, а тут 3 наелся, это противоречие! In statement: "Попугай заведомо наестся десятью орехами и заведомо останется голодным, съев лишь два" Where do you see 3? Sorry Test #7 2 4 s 3 s Correct answer is 3, not 'Inconsistent' #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n,k,mh=0,otg=999; string s; vector<int>v; cin>>k; for(int i=1;i<=k;i++) { cin>>n; cin>>s; if(s=="hungry") { if(n>mh) mh=n; } else v.push_back(n); } if(v.size()) { for(int i=0;i<v.size();i++) { if(v[i]>mh&&v[i]<otg) otg=v[i]; } if(otg==999) cout<<"Inconsistent"<<endl; else cout<<otg<<endl; } else cout<<"10"<<endl; return 0; } Edited by author 02.11.2010 12:52 Edited by author 02.11.2010 12:52 #include <iostream> #include <string> #include <algorithm> using namespace std; const int N=100; int main() { int n,i,k; int x[N],y[N]; string z[N]; int total_s=0,total_h=0; cin>>n; cin>>ws; for(i=0;i<n;i++) { getline(cin,z[i]); } for(i=0;i<n;i++) { if(z[i][2]=='s') { y[total_s++]=z[i][0]-48; } if(z[i][2]=='h') { x[total_h++]=z[i][0]-48; } } sort(x,x+total_h); sort(y,y+total_s); if(total_s==0) { cout<<"10"<<endl; } else { if(y[0]<=x[total_h-1]) { cout<<"Inconsistent"<<endl; } else { cout<<y[0]<<endl; } } return 0; } На 7 или на 8 тесте ошибка но все тесты что я видел все правильно идут вот код: var state:string; n,i,k,max,min:integer; h,s:boolean; begin readln(n); min:=10; max:=3; for i:=1 to n do begin readln(k,state); delete(state,1,1); if state='hungry' then begin if h=false then begin max:=k; h:=true; end; if max<k then max:=k; end else begin if s=false then begin min:=k; s:=true; end; if min>k then min:=k; end; end; if max>=min then write('Inconsistent') else write(min); end. I have got wa 14 and don't know why Edited by author 29.12.2008 18:33 Bilol, Well, its almost a year now, but will write it down anyway. My WA program program was generating this: Input 5 3 hungry 4 hungry 5 hungry 5 satisfied 6 hungry Output 5 But the correct answer is Inconsistent. So, try to find maximum hungry value and minimum satisfied value and apply the given conditions. Varun I got AC at this easy problem but I'm just interested: how did you read input? I used this: for (int i=0; i<n; i++) { scanf("%d %c",&x,&ch); getline(cin,tmp); //something... } But I think it's stupid way of doing this, can someone with C++ AC show me his reading part? Edited by author 07.08.2009 18:01 char s[20]; for (int i=0; i<n; i++){ scanf("%d %s",&x,s); ... } well, this is good but i wanted something else... Is there anything in C++ which works as ReadLn in Pascal. I mean something which read and ignore characters before next newline character? I thought something like scanf("%d %c\n",&x,&ch) works but it doesn't. getline works fine but it requires to declare one more string variable and works slow. Also, can you explain me how scanf("%s",s) works? cin.ignore(maxCharsNum,delimiterChar); It ignores "maxCharsNum" symbols if there is no "delimiterChar" among them. Else it ignores all symbols before "delimiterChar" (and "delimiterChar" also). char s[N]; scanf("%s",s); Reads symbols before meet space, '\n' or '\t' and puts '\0' in the end. It doesn't stop reading if number of symbols is greater than N. So, N must be always greater than maximal number of symbols in string. Edited by author 07.08.2009 21:28 Did you test it with sample? What the ... My program working right on sample tests, but WA#1 xD try n = 1 Oh, yes! =) Now I got AC. P.S. If your program works corrects on sample teste, but you got WA1: Most likely, you reading superfluous space in string variable. Try to solve now :) Edited by author 24.07.2009 12:48 xD Edited by author 15.05.2010 17:53 Edited by author 27.06.2010 19:48 Edited by author 27.06.2010 19:48 Edited by author 27.06.2010 19:49 Edited by author 27.06.2010 19:49 Edited by author 27.06.3009 19:49 Edited by author 27.06.2009 19:49 Read problem statements. you should write 10 I have done it this way and got AC [CODE DELETED] Edited by author 27.10.2008 22:31 try this tests: 2 3 hungry 3 satisfied the answer is "Inconsistent" 2 3 hungry 4 hungry the answer is "10"; if you understand you will get AC; #include <iostream> #include <string> using namespace std; int main() { int n,k,temp=100,temp1=100,need = 100,need1 = 100; char s[15]; int asd = 0; string s1; cin >> n; for (int i = 0; i < n; i++) { cin >> k >> s; s1 = s; if (s1 == "satisfied") { asd = 1; if (n == 1) { cout << k; exit(0); } temp = k; if (temp < need) need = temp; } if (s1 == "hungry") { temp1 = k; if (temp1 < need1) need1 = temp1; } } if (asd == 1) { if (need >= need1) cout<<need; else if (need1 == 100) cout <<need; else cout<<"Inconsistent"; } else<<"Inconsistent"; return 0; } try this test: 1)in: 0 out: 10 2) in: 2 3 hungry 5 hungry
out: 10 thx for test i forgot this "Известно, что Попугай заведомо наестся десятью орехами и заведомо останется голодным, съев лишь два." and change code from
else cout<<"Inconsistent"; to else cout<<"10"; but now have WA8 //// can you show me better algorithm to solve this problem? my mail : grumpy@doda.uz Edited by author 25.10.2008 19:21 Edited by author 25.10.2008 19:21 try: 2 1 hungry 1 satysfied your test is not correct!!! may be you mean: 2 3 hungry 3 satysfied ??? No, I made mistake again because bounds 3-9 to stochastic. I meant about important test: 2 3 hung 5 hung answer:10 Edited by author 27.10.2008 19:19 if Hungry >= Satisfied answer will be "Inconsistent"; else min(Satisfied); if no information about Satisfied then answer "10" thats all; test 2 1 hungry 1 satisfied my solve show me answer 1 but it should be 10 because he will hungry even he eat 2 test 2 3 hungry 3 satisfied answer 3 is it right? Edited by author 25.10.2008 20:57 Edited by author 25.10.2008 21:00 right answer is: Inconsistent Igor Do you have ICQ? my number is 301-717-834 Я думаю 1- голоден 1 - сыт... таких чисел не может быть по условию... сказано же от 3 до 9... Я все варианты перепробовал в том числе и свашими.. и все равно на 15 тесте ошибка... Here is my code... Look at please. Uses SysUtils; var h: array [1..9] of byte; s: array [1..9] of byte; n,i: integer; min,max: integer; s1: string; ch: integer; ok: boolean; begin //Assign(input,'input.txt'); reset(input); readln(n); min:=0; fillchar(h, sizeof(h),0); fillchar(s, sizeof(s),0); ok:=true; max:=100; for i:=1 to n do begin readln(s1); ch := strtoint(s1[1]); Delete(s1,1,2); if (s1 = 'hungry') then h[ch]:=1; if (s1 = 'satisfied') then begin s[ch]:=1; ok:=false; end; end; if ok then begin writeln(10); exit; end; for i:=3 to 9 do begin if h[i]=1 then max:=i else if (s[i]=1) and ((min<max) and (max<100) or (min=0)) then min:=i; end; if (min = 0) and (max=100) then writeln('10') else if (min > max) or (max = 100) then writeln(min) else writeln('Inconsistent'); I made stupid mistake. I meant 2 3 h 3 s of course. This test I produced when thinking about Wa8 and after got AC. P.S. I think you must be graitfull to us. With our help you gone over Wa8. Did you tried the text: 2 2 hungary 5 hungary The answer is 10 because no information about satisfaction. Edited by author 25.10.2008 22:23 Elmurod misol to'g'ri yechdingma? 1-2 ta test ayt mening yechganimda 1-testdan qaytyapti my mail:bunyod-real@mail.ru Post there your code ... and we will try to help you ... |
|