Общий форумfor i = 1.. for j = 0..n-i; atoi() strings str[j...j+i] to num[j] sort(num, num + n - i + 1) find num[j] + 1 < num[j+1] and output num[j]+1 There is a solution O(N) without sorting: check numbers that has length at most 6 digits... Help plizz :( maximum number of true predictions can be 0. Vadik will pay 5 dollars to all, if there were no any true predictions. Thanks! I got AC. But it makes me wonder really makes me wonder :) Edited by author 22.10.2011 01:44 any idea what test case 13 maybe? any idea what test case 13 maybe? So easy with Java and ArrayList) using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace timus { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int s = 0; for (int i = 1; i <= Math.Abs(n); i++) { s += i; } if (n >= 1 && n <= 1000) { Console.WriteLine(s); } else if (n <= 0 && n >= -1000) { Console.WriteLine(-(s - 1)); } } } } Edited by author 05.12.2011 18:34 I guess, the test42 is the following: 2 0 1 1 0 thank you, it helped) (WA 42) #include <stdio.h> int main(){ int i,n,j,m[151],d; scanf("%d",&n); for(i=0;i<n;++i) scanf("%d",&m[i]); for(i=0;i<n;++i) for(j=0;j<n;++j) if(m[i]<m[j]){ d=m[i]; m[i]=m[j]; m[j]=d; } d=0; for(i=0;i<n-3;++i) if(m[i]==m[i+1]) if(m[i+1]==m[i+2]) if(m[i+2]==m[i+3]) if(m[i+3]>=600) if(m[i+3]<=700){ ++d; i=i+4; }
printf("%d",d); return 0; } Why WA2? May be, someone had same problem? My program here: [code deleted] Edited by author 28.03.2005 22:30 Edited by moderator 02.01.2020 18:24 Yahooo!!! I have surmised! "inclination" - it is absolute value, without sign! But author should mentioned it in the task, in my opinion. Yes,you're right! Thank you very much.! The author should mentioned.It is a big problem.I think. yeah,I think it is important. var hash:array [1..5001] of longint; i,j,k,n,m,ch,zap:longint; s:string; begin readln(n); for i:=1 to n do begin readln(ch); inc(hash[ch]); end; readln(s); readln(k); for i:=1 to k do begin readln(zap); for j:=1 to 5000 do begin if zap<1 then begin writeln(j-1); break; end else zap:=zap-hash[j]; end; end; end. WA Test #2.... the main thing wrong with your code is it's in pascal :D A - first divider of K, which is more or equal than 3 (A>=3) We need write A-1. AC - 0.578 and 134 KB Edited by author 27.03.2010 14:34 I made the same, but WA on test 11. What's the matter? I see a solution in another topic, there used I64. Oh, don't tell me to use I64. 10^8 is involved to int. Why does not it work? <code> #include <stdio.h> int K; int L; int main() { scanf("%d", &K); L = 2; while (K%(L+1) != 0) { if ((L+1)*(L+1) > K) { printf("%d\n", K-1); return 0; } L++; } printf("%d\n", L); return 0; } </code> Edited by author 18.08.2011 03:22 At last. I undestood. Expression "if ((L+1)*(L+1) > K)" not correct, because we skip 2. Since for K=8, we return 7, when the correct answer is 3. Edited by author 18.08.2011 03:56 > I made the same No I see u didn't :) The actual solution is 5 lines, 4 of which are declarations and i/o Edited by author 27.11.2011 17:43 Given A B N D=GCD(A,B); then N/=D and N*=D and N/=D;because we must find closed number to N; A/=D; B/=D; then full search if(A>B) for(i=0;i<=N/A;i++){type here equation Ai+By=N, try to find x and y} else for(i=0;i<=N/B;i++){type here equation Ax+Bi=N , try to find x and y} *trick:in loop, if Ax+By=N then break,that means we have already found number.. Edited by author 24.03.2011 01:44 I did how you said, and when I tried to pass this solution without trick, I got TL#10, with trick got AC in 0.031 sec. I really don't understand, how this trick can give so impressive speed-up? Explain me pls!! Let's suppose A >= B, (A, B) = 1; Then there is such (0 <= i < b) that (a * i) % b = (N % b). On the other hand, i <= N / a. So, i <= min(N / a, b - 1) <= min(N / a, a - 1) <= sqrt(n); program Project2; var a:array[1..100,1..100] of integer; k,p,n,i,j,s:integer; begin readln(n); k:=0; p:=n-1; for s:=1 to (n*2-1) do begin for i:=1 to n do for j:=1 to n do if j-i=p then begin k:=k+1; a[i,j]:=k end; p:=p-1 end; for i:=1 to n do begin for j:=1 to n do begin write(a[i,j]); write(' ') end; writeln end; end. 1, 2, 3, ..., n 1, n+1, 2n+1, ..., (m-1)*n+1 I have even written a testing program to verify this and it reports that there is no mistake. I checked this on a few inputs like (2, 3), (1, 50), (50, 1), (50, 50) and it always seems to be correct. Can anybody give me a hint on where my mistake is? UPD: Got AC after changing to this: 1, 2, 3, ..., n n+1, 2n+1, ..., m*n+1 The question remains. WTF? UPD2: Read the statement again and figured this out. All number should be different. In my solution, 1 was repeated twice. Edited by author 26.11.2011 22:13 This is my first solution. I don't know if I am doing everything all right. I use the Free Pacal Compiler. Does the output of my solution have to be real, rounded to an integer, or just integer? This is my solution program Project2; var x,y:array[1..100000] of longint; r:array[1..100000] of longint; d:longint; n,i,j:longint; begin readln(n); for i:=1 to n do readln(x[i],y[i]); for i:=1 to n do r[i]:=0; for i:=1 to n do for j:=1 to n do if i<>j then r[i]:=r[i]+(abs(x[j]-x[i])+abs(y[j]-y[i])); d:=0; for i:=1 to n do begin r[i]:=r[i] div (n-1); d:=d+r[i] end; d:=d div n; writeln(d) end. if (A==B) then distance to the AB is a distance to point A (or B) :) Not only. I get WA17 too. When I change > to >= in checking of angles CAB and CBA I get AC. What is there in this test? This solution now gets WA38 var ar : array[1..10,0..9] of longint; n,i,a1,a,j,max : longint; begin readln(n); for j := 1 to n do begin readln(a); i := 1; while a <> 0 do begin a1 := a mod 10; a := a div 10; inc(ar[i,a1]); inc(i); end; end; n := 0; for i := 10 downto 1 do begin max := 0; for j := 1 to 9 do if ar[i,j] > ar[i,max] then max := j; n := n*10 + max; end; writeln(n); end. #include<iostream> using namespace std; int main(void) { int input,weight,temp,i; long int sum=0; cin>>input; if(input<1 && input>21) exit(0); int ary[20]; for(i=0;i<input;i++) { cin>>weight; if(weight>=1 && weight<=100000) { ary[i]=weight; sum+=weight; } } for(i=0;i<input-1;i++) { for(int j=0;j<input-i-1;j++) { if(ary[j]>ary[j+1]) { temp=ary[j]; ary[j]=ary[j+1]; ary[j+1]=temp; } } } int x=input-1; if(x==0) { cout<<ary[x]; exit(0); } long int k1,k2,middle; middle=sum/2; k2=ary[x]; k1=ary[x-1]; int r=0; int bol=0; for(i=input-3;i>=r;) { if((k1+k2)<=middle) { k2=k1+k2; k1=ary[i]; i--; } else if(k1<k2) { if(bol==0) { k1+=ary[r]; r++; bol=1; } else { k1+=ary[i]; bol=0; i--; } } else { if(bol==0) { k2+=ary[r]; r++; bol=1; } else { k2+=ary[i]; bol=0; i--; } } } if(k2>k1) cout<<k2-k1; else cout<<k1-k2; return 0; } can u pls explain ths code..atr sortng wht hv u dn?? can u pls explain ths code..aftr sortng wht hv u dn?? if(input<1 && input>21) ??? is it possible? Consider the following situation : 3221 1) k2=3,k1=2 2) k1+k2=5>4 bol=0 k2>k1, so k1=k1+1=3, k2=3, bol=1 3) k1+k2=6>4 bol=1 k1>=k2, so k2=k2+2=5, k1=3, bol=0 -> result = 2, but 31 | 22 -> 0 !!! the description of the problem is so unclear. the rule of the game is that you take a stone through a stone( just a stone, but not two ) and get to a place which is empty, and the stone which had been passed is taken away. sorry for my poor english. Edited by author 24.11.2011 21:14 Even if not - what changes? Yes, I agree - anything ) Yes, he can. And solution of this problem becomes too easy... even funny :) Yes, he can. Sandro can teleport to origin point. Edited by author 02.07.2011 01:25 Edited by author 02.07.2011 01:25 Sandro is AT the origin point :) Yes, it's very easy :) Thanks for idea! #include <iostream> #include <cmath> #include <vector> #include <algorithm> using namespace std; int main(int argc, char** argv){ long long int n; cin>>n; vector<char> v; if(n == 1){ cout<<1; return 0; } else if(n == 0){ cout<<10; return 0; } int cur = 9; while(n!=1){ bool flag = false; for(; cur>=2; --cur){ if(n/cur*cur==n){ flag = true; v.push_back(cur); n = n/cur; cur = 9; } } if(!flag){ cout<<-1; return 0; } } sort(v.begin(), v.end()); long long int a = 0; for(int i = 0; i<v.size(); i++){ a = a*10 + v.at(i); } cout<<a; } |
|