Общий форумvar n,i: integer; x1,x2,y2,y1,xx,yy,e,r: real; begin readln(n,r); readln(x1,y1); yy:=y1; xx:=x1; for i:=2 to n do begin readln(x2,y2); e:=e+sqrt(sqr(x2-x1)+sqr(y2-y1)); x1:=x2; y1:=y2; end; writeln((round((e+2*3.14159*r+sqrt(sqr(xx-x1)+sqr(yy-y1)))*100))/100); end. I'm using Heavy light Decomposition an I'm getting ML in test 9 WHY ???? could you give me test #7? I can not understand what is wrong! I have Wa#4. Please help me! #input 5 5 ooooo ooooo ooooo ooooo ooooo 2 1 13 #output ??? 5 5 ooooo ooooo ooooo ooooo ooooo 2 1 13 ans: Experiment #1: North: 4, South: 0, East: 20, West: 0 Experiment #2: North: 2, South: 2, East: 10, West: 10 Edited by author 20.11.2014 20:26 I use fgets to read from stdin, when I try to store name in an array with length 201, i got WA 3,but when I changed the length to 210, I got AC, who can tell me why? i got it: if the name has exactly 200 symbols, the name and the newline will be read into two strings. Hi, This is my code: #include <iostream> #include <vector> #include <cmath> #include <iomanip> using namespace std; int main() { vector<int> V; V.resize(0); int n; cin >> n; while( n != EOF) { V.resize(V.size() + 1); V.push_back(n); cin >> n; } cout << setprecision(4) << fixed ; while(V.size() > 0) { n = V.back(); V.pop_back(); cout << sqrt(n) << endl; } return 0; } Could someone please tell me why the memory got exceeded here ? The stream is just 256 KB, right ? Regards, Ankita Кт-т упрлс тк услв псть в чм прблм В пршлм гд бл прфсср "Е.Бен", в этм "ЗБС". Нцнзрн брнь. нжн длг крть, чтб т рскрть - вбщ н дгдлс... Edited by author 26.10.2014 14:08 збс же придумал автор?! ЗБС!) Give me some tests please Not related to WA5, but to WA4 - perhaps it helps anyway: I got wa4 when forgot to add the advantage of each apartment, to the total value, before comparing to current max. I got WA5. But I have passed it. My error was in copypast. When I was comparing current maximum, I used wrong massive. I want to calculate maximum living along in 2 bedroom apartment massive , but I took values from one bedroom apartment massive :( #include <stdio.h> #include <stdlib.h> struct Team { int id; int m; }; int main() { int n; struct Team * res;
scanf ("%d", &n); res = (struct Team*)malloc( n * sizeof(struct Team) );
for (int i = 0; i < n; i++) scanf ("%d %d", &res[i].id, &res[i].m); struct Team tmp; for (int i = 0; i < n-1; i++) for (int j = 0; j < n-1; j++) if (res[j].m < res[ j+1 ].m) { tmp = res[j]; res[j] = res[ j+1 ]; res[ j+1 ] = tmp; } for (int i = 0; i < n; i++) printf ("%d %d\n", res[i].id, res[i].m); return 0; } Simple test for programs with verdict WA #14: Sample input: 0 2 1 1 Sample output 1 2 Your program outputs "-1"? Find your simple stupid mistake!!! Edited by author 05.11.2005 18:58 Thank you!I got AC!!!Before testing your testcase,my program outputed "2" :) It helps a lot. Thank you! BTW. It's not a valid test case. Here's a valid one. input: 3 3 3 1 1 output: 2 3 How to prevent TLE? I use LinkedList (can AddFirst and AddLast) and use max size of set = n. I'll give you the same hint that helped me see the way: Note that there are a maximum of 10^6 operations. I use this fact: when copy operation occurs then I copy not whole set but only part of set (so size of set always <= n). But this doesn't prevent from TLE. So, how to copy rapidly (I copy element by element)? Hmm that sounds like the right idea, you might double check that your code matches your idea correctly. > 1.031 32 120 KB Looking at your submit data, you may need to be more aggressive in implementing your idea. Edited by author 24.10.2012 17:26 Now I use array with length 2*n instead of LinkedList. So, I decrease memory: >1.015 5 912 КБ But how to decrease time? =) Copy operation takes most time, but each time size of my array (amount of useful elemenets that can be pop) is not more than (n - i) elements. So, how to optimize copy operation? It's really hard to say without seeing code. If you're correctly managing copies like you say, you shouldn't TLE. Seems like you have a simple bug somewhere. Try creating more perosnal test cases that focus on copies to start with. I've overwritten my code from C# to C++ and use memcpy for quick copying but TLE42 again =). So, could you please send me your solution or tell me your mail to check my solution? My mail is on my profile page (hyperlink) From the site FAQ on C/C++: An example of how to use input/output is given above. C++ programmers may always choose between two input/output libraries: standard (scanf, printf) or stream (cin, cout) input/output. Stream input/output is easy to use, but it works much slower than standard input/output. This may even cause receiving the Time limit exceeded verdict. Therefore, if you see that a problem requires reading a lot of input data (for example, more than a megabyte) or a large output is expected, then you should better use standard input/output. Thank you, using of scanf and printf leads to AC. This is bad problem when your algorithm is not so neccessary as quick reading and writing. For C# coders: use Console.In.ReadToEnd - for reading whole input file, and use only once Console.Write for writing answer, and you'll get AC. I just can't understand, when I submit my code using g++4.7.2 c++11, I got TLE42, but vc++2010 or g++4.7.2, I can AC 0.64s. Then I try other problems I find g++4.7.2 is the best. Edited by author 26.04.2013 15:20 In Java use PrintWriter instead System.out.println. I have TLE 1.015 with System.out.println, and I have time 0.703 with PrintWriter. you can use to check "YES" that simple DSU algorithm. because DSU algorithm gives us all cycle, knot, multigraph ... so on
Можете отправить работающую программу,если не сложно.Долго уже пытаюсь,не получается:( Вот код: #include <iostream> using namespace std;
int main() { int k, n; cin >> k >> n;
int a; int sum = 0; for( int i = 0; i < n; i++ ) { cin >> a; sum += a; }
if( ( sum - n * k ) < 0 ) cout << 0; else cout << sum - n * k;
return 0; } на тесте 6 загибается в чом проблемма? 4 3 1 5 6 Answer isn't 0, True Answer is 3. почему 3? 4 3 1 5 6 Потому что в первую минуту прошла только 1 машина. Во вторую прошли 4 машины и 1 осталась на 3ью минуту. А в 3ью минуту Должны пройти 6+1=7 машин, а может только 4. 7-4=3. У меня ответ 3. А тест не проходит. Can you tell me why the answer is 3 but 0? use Google translate))) They tell about answer))) |
|