Общий форумВот такой код. Хочу найти ошибку. Но найти не могу. Для всех перебранных случаев все вычисляется как надо. Не пойму как пройти тест. #include <iostream> using namespace std; int foo(short pos); int main() { long i; short int y; cin>>i; for(int cnt_1 = 0; i > cnt_1; cnt_1++){ cin>>y; cout<<foo(y)<<" "; } } int foo(short int pos) { short int res(1); short int i(0); do { res = res + i; i++; } while(res<pos); if(res != pos) return 0; else return 1; } Какая тут ошибка? #include<iostream> #include<vector> #include <cmath> using namespace std; int main() { int n1,n2,n3,x; int sch=0; vector<int>nv1; vector<int>nv2; vector<int>nv3; cin>>n1; for(int i=0; i<n1; i++) { cin>>x; nv1.push_back(x); x=0; } cin>>n2; for(int i=0; i<n2; i++) { cin>>x; nv2.push_back(x); x=0; } cin>>n3; for(int i=0; i<n3; i++) { cin>>x; nv3.push_back(x); x=0; } for(int i=0; i<n1; i++) { for(int j=0; j<n2; j++) { for(int k=0; k<n3; k++) { if((nv1[i]==nv2[j])&&(nv2[j]==nv3[k])) { sch=sch+1;} } } } cout<<sch<<endl;
} Because 64 * 10 ^ 9 is too many operations for 0.5 seconds :) Please provide more test cases, the one provided is very naive and it passes easily, I get WA on #4, although someone provided it in the discussion and my code passes it. Thanks same thing. give some tests, please I don't have tests, but my bug was the following: when I sorted sequences, ones with negative balance should be sorted in the symmetrical way with the sequences with positive balance, and I've compared them wrongly. Edited by author 04.11.2012 17:36 Actually, You can solve this problem with DP[2][N]. (it's a little strict Memory Limit in compare with the other DP problem in Java.) You can solve it using DP[N]. My solution for a table size of 1000 to 1000 is 4.07 MB of memory. What should I do? You shouldn't use table 1000*1000. It could be solved using table 1000*2 int x[100],y[100],max[100]; I used: bool table[1000][1000]; which is 0,95367431640625 MB. table[i][j] = 1, if the respective quarter can be crossed diagonally, and '0' otherwise. I also used an array a[1001], in which to store the distance, and several auxiliary variables. The total memory used is 1128 KB. The answer I get for 5 is 41616. I do not understand why this is not good. Can anybody tell me the right answer for 5? Thx. Add '1' to the input number and see if it's lucky, i.e. if the sum of the first 3 digits is the same as the sum of the second 3 digits of the newly formed number. Subtract '1' from the input number and check the same. Output 'Yes' if the newly formed number satisfies the condition, and 'No' otherwise. How can I quickly build adjacency matrix befor using bfs for this problem. I have TLE#6,#10,#12 for this problem. Any algorithm please! Adjancency matrix will require 10000^2 elements. It's too many, u won't fit in memory limit. Use adjancency list instead. For example, if you use C++, you can represent it as an array of vectors, where the vector at index i contains numbers of vertices that adjanced to the vertex with number i. for (int i=0; i<N; i++) { int a, b; cin >> a >> b; vect[a].push_back(b); vect[b].push_back(a); } ok, there are vectors. but how insert this vectors to the Deikstra algorithm? brute force is 20 lines AC. how long code with formula? Are there many possible answers? For example in the test example my program gets the answer: 0000 (do nothing) 0111 (insert 1 at the end) 1010 (change the last 1 in 0; I suspect that this 1 was initially a 0 and now, due to the noisy line, it's a 1) 1101 (erase the last 1) the total sum of positions is 20, which is a multiple of 5 = 4 + 1 Did I get something wrong? I not, which solution should I print? And is it possible not to have any solution? import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class No1068 { public static void main(String[] args) throws Exception { BufferedReader rd=new BufferedReader(new InputStreamReader(System.in)); PrintWriter wr=new PrintWriter(new OutputStreamWriter(System.out)); StringTokenizer line =new StringTokenizer(rd.readLine()); Integer n=Integer.parseInt(line.nextToken());
if (n>0) wr.println((n*(n+1))/2);
else { n=Math.abs(n); wr.println(1-(n*(n+1)/2)); } wr.close(); System.exit(0);
} } How to solve this problem?I use trie tree and get MLE #2!!!!!!!!!!! Edited by author 26.08.2012 09:02 Edited by author 26.08.2012 09:02 I use suffix array and get AC WHY? type hlist=^list; list=record data: longint; l,r: hlist; end; var n,i:longint; a:array[1..3000] of longint; head: hlist; procedure add(var v:hlist; x:longint); begin if v=nil then begin new(v); v^.data:=x; end else if x>v^.data then add(v^.r, x) else add(v^.l, x); end; procedure draw(var v:hlist); begin if not (v=nil) then begin draw(v^.r); draw(v^.l); write(v^.data,' '); dispose(v); end; end; begin readln(n); for i:=n downto 1 do read(a[i]); for i:=1 to n do add(head, a[i]); draw(head); end. The same error! I don't understand why and what does mean acess violation? Help, please! program p1136; type arbore=^nod; nod=record info:word; left,right:arbore; end; var t,r,q:arbore; n,i:integer; a:array [1..3000] of word; procedure postordine(t:arbore); begin if t<>nil then begin postordine(t^.right); postordine(t^.left); write(t^.info,' '); end; end; begin readln(n); for i:=n downto 1 do read(a[i]); new(t);new(q);new(r);t^.info:=a[1]; for i:=2 to n do begin r:=t; while q<>nil do begin if a[i]>r^.info then begin new(q);q:=r^.right;end else begin new(q);q:=r^.left;end; if q<>nil then r:=q; end; new(q);q^.info:=a[i]; if r^.info<a[i] then r^.right:=q else r^.left:=q; end; postordine(t); end. Should there be a teddy Hater in team of Holden? Edited by author 31.10.2012 15:36 yes, if Holden is no Hater. Could you give me case for test 14? Thank you! each window light travels in both directions, or one? 1 2 0 2 Is answer of second child to himself means "circle" ? This test is incorrect. If a child says that he is innocent then mother write down number 0 for his answer. So test could look as follows: 1 2 0 0 Certainly, answer is NO |
|