Общий форумI get access violation when i use array of size N = 500000. # include <stdio.h> # include <iostream> # include <algorithm> # include <math.h> # define max1 50009 # define max2 75009 using namespace std; int path[max1][2]; int n,m,a,b,c,path1,path2; int ans[max2]; int min1(int x,int y) { if(x<y) return x;
return y;
} int main() { cin>>n;
for(int h=0; h<n-1; h++) { cin>>a>>b>>c;
a++; b++;
if(max(a,b)%2==0) path[min1(a,b)][0]=c;
else path[min1(a,b)][1]=c; }
cin>>m;
for(int h=0; h<m; h++) { cin>>a>>b;
a++; b++;
path1=0; path2=0;
while(b!=a) { int s1=1,s2=1; int d1=s1<<((int)log2((double)b)); int d2=s2<<((int)log2((double)a));
if(d1<=a) { if(a%2==0) path1+=path[a/2][0];
else path1+=path[a/2][1];
a/=2; }
if(d2<=b) { if(b%2==0) path2+=path[b/2][0];
else path2+=path[b/2][1];
b/=2; }
ans[h]=path1+path2;
}
}
for(int h=0; h<m; h++) cout<<ans[h];
} Edited by author 25.09.2012 13:35 #include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> ivec; vector<string> svec; int val; string s; for (int i = 0; i < n; ++i) { cin >> val; ivec.push_back(val); cin >> s; svec.push_back(s); } if (n == 0) { cout << 10 <<endl; return 0;} if (n == 1) { if (svec[0] == "satisfied") { cout << ivec[0] << endl; return 0;} if (svec[0] == "hungry") { cout << 10 << endl; return 0;} } int hungry[100]={0},satisfied[100]={0}; int hungry_num=0,satisfied_num=0; for (int i = 0; i < n; ++i) { if (svec[i] == "hungry") { hungry[hungry_num++] = ivec[i]; } if (svec[i] == "satisfied") { satisfied[satisfied_num++] = ivec[i]; } } sort(hungry, hungry+hungry_num); sort(satisfied, satisfied+satisfied_num); if (hungry[hungry_num-1] >= satisfied[0]) { cout << "Inconsistent" << endl; return 0; } cout << satisfied[0] << endl; return 0; } When n == 0; What is the answer? if n==0 answer is 10 Edited by author 24.09.2012 21:58 Maybe this: the minimal length of the sides of the map is 100 or that it could be one map. The spots (or pictures) maybe have points with negative coordinates? Пятна (или картины) могут иметь точки с отрицательными координатами? Edited by author 14.05.2007 16:56 No, they haven't. You are wrong. All spots must have integer positive coordinates of centers only. For example the spot 100 1 1 is valid. And it is covered by a picture with angle coordinates (-99,-99)-(101,101). Please, write in the statement that coordinates of pictures can be negative. What answer should be for test 4 1 1 1 1 1 1 1 1 1 1 1 1 ? my is 1 1 1 .... but still get WA on WA3 or WA2 (depends on sth) 4 1 1 1 1 1 1 1 1 1 1 1 1 Test is incorrect "None of the routes shared the same section of road" I think this test is correct. There can be 4 different sections of road connecting station 1 with itself. just put all the numbers in a array of boolean. var n,i,caint:longint; b:array[-100000..100000]of boolean; begin readln(n); fillchar(b,sizeof(b),false); for i := 1 to n do begin readln(caint); b[caint]:=true; end; readln(n); for i := 1 to n do begin readln(caint); if b[10000-caint] then begin writeln('YES'); halt; end; end; writeln('NO'); end. Edited by author 10.09.2009 08:34 It is O(n), not O(1) And there's another O(n) solution for this problem, which requires only O(n) memory instead of O(v) in your case, where v is max value of a_i. Yes , SkidanovAlex right. O(n). Enter your name above ("Имя автора"), click "Search"("Поиск"), find your account there and click it. There your can find full list of your problems (accepted, not accepted and that you didn't try) DFS - TL22 1.046s BFS - Accepted 0.031s Using DFS for shortest path problem? Great job! DFS have so clean and short realisation that i can't think about BFS even if it is required! :D The cook must cook the one steak during 2 minutes (each side during 1 minute). Right? In example n = 3, k = 2, then: * at first step he cook 2 stake during 2 minutes; * at second step he cook 1 stake during 2 minutes; Answer = 2 + 2 (minutes), but in example 3? If try to send solution based on above logic, checker answered with mistake. Probably checking occurs on this way (all test passed): answer == (k >= n) ? 2 : n * 2 / k + ((n*2 % k == 0) ? 0 : 1) but, more correctly (in my opinion) variant: answer == (k >= n) ? 2 : n * 2 / k + ((n % k == 0) ? 0 : 1) Your solution to n=3, k=2 is not optimal. Hint: examine different orderings, trying to keep the frying pan as full as possible all the time. In your solution, you have the frying pan half empty twice. STL map rulz for this probl Edited by author 14.02.2008 20:29 Edited by author 14.02.2008 20:29 I think this problem can be solved easy without STL ;) Yes but STL map<string,int> is really great for string counting problems like this, and leads to short, clear solutions. if you have only one experiments "X satisfied" then the answer is always X if you have only one experiments "X hungry" then the answer is always 10 If n == 0 ? What is the anwaer? Somebody already answered this in the discussion, it's 10 read the text! The text is inadequately worded, it does not specify the process for shoeing the right feet after the left feet are filled. The solver must assume that the process for filling the right feet is the same as for filling the left feet. All solutions now get WA1 / WA13, even those, which have been accepted earlier. It's a judge error or just a rejudge coming? Edited by author 22.09.2012 17:21 Sorry, we have broken test #13. It's fixed now. Solutions are rejudged. check this tests for "Not a floating point number" - 1 -. 1 -.e0 1 -.1e 1 #123 1 --123 1 -1.e6 1 And last one (when I fixed this, I got Accepted): -e20 1 Of course this is not an exhaustive list of possible bugs. Good luck, guys! does anyone knows test 3? thank you! import java.util.Scanner; public class MEGA { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int capacity = sc.nextInt(); int minutes = sc.nextInt(); int stoppedcars = 0; for (int i=1; i<=minutes; i++) { int thisminutecars = sc.nextInt(); if (thisminutecars > capacity) stoppedcars = thisminutecars - capacity; if (thisminutecars < capacity) stoppedcars = stoppedcars - (capacity - thisminutecars); } if (stoppedcars < 0) stoppedcars = 0; System.out.println(stoppedcars);
} } Edited by author 17.09.2012 17:51 Step through in the debugger and see if the changes to stoppedcars makes sense to you. Do you properly handle cars left over from previous minutes? I wrote an iterative primes generator using a 2-3-5 wheel for candidate generation and a priority queue for storing composite sequences. I feel silly seeing all the ACs for trial division. But at least now I know about wheel generators and iterative prime generation :). program ural1078(input,output); type node=record x,y:longint;num:longint;end; var n,i,j,max,maxi:longint; f:array[1..500]of longint; c:array[1..500]of longint; l:array[1..500]of longint; a:array[1..500]of node; procedure sort(l,r:longint); var i,j:longint;k,temp:node; begin i:=l;j:=r;k:=a[(l+r)div 2]; repeat while a[i].x>k.x do inc(i); while k.x>a[j].x do dec(j); if i<=j then begin temp:=a[i]; a[i]:=a[j]; a[j]:=temp; inc(i);dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; procedure print(x:longint); begin if x=-1 then exit; print(c[x]); write(a[x].num,' '); end; begin readln(n); //if n=0 then writeln(0); for i:=1 to n do with a[i] do begin readln(x,y);num:=i; end; sort(1,n); fillchar(c,sizeof(c),255); for i:=1 to n do begin f[i]:=1;l[i]:=0; for j:=i-1 downto 1 do if (a[i].x<a[j].x)and(a[j].y<a[i].y) //Take Care!!! then begin if f[j]+1>f[i] then begin f[i]:=f[j]+1; c[i]:=j; end; end; end; for i:=1 to n do if f[i]>max then begin maxi:=i;max:=f[i]; end; writeln(max); print(maxi); end. |
|