Общий форумConsider the following test: 7 Wayne 2 Bruce Dick Bruce 1 Brown Dick 1 Grayson Brown 1 Gordon Grayson 1 Gordon Gordon 1 Stephanie Stephanie 1 Wayne Master Wayne is going to disguise as Batman and stop the Joker! I must prepare the Batmobile for his quest! My solution fails to print Stephanie as a person who received the tweet about the earthquake. My solution uses a shortest path algorithm and that is why it takes into consideration only the shortest tweet reaching Gordon(the tweet sent by Grayson). So Gordon will try to send the tweet that he received(on the path Wayne Dick Grayson) preappended with "RT @Grayson: "(which is 13 characters long), totalling 141 characters. So the algorithm concludes that Stephanie will receive no tweet. But if we take the path Wayne, Bruce, Brown to Gordon, Gordon will receive a longer tweet than on the other path, but Stephanie will receive a tweet totalling 140 characters so she will actually be notified by a tweet too, although my algo fails to notice this. I believe that there are great chances that other shortest path algos implemented by other users behave the same, so please try to consider improving the tests with a test similar with mine, Regards, Ciprian Edited by author 15.10.2012 00:16 Your test was added. Thank you. if you get WA 4 and you solve the problem from the end, than (maybe) you must take into account that sensor return only possitive number or null ans intermediate value can be >= 0. Edited by author 15.10.2012 02:29 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int n = sc.nextInt(); String S[] = new String[n]; for (int i = 0; i < n; i++) { S[i] = sc.next(); } int m = sc.nextInt(); String[] S2 = new String[m]; for (int i = 0; i < m; i++) { S2[i] = bf.readLine(); } int count = 0, tempcont = 0; boolean isFineded = false; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { StringTokenizer st = new StringTokenizer(S2[i]); count -= tempcont; tempcont = 0; while (st.hasMoreTokens()) { tempcont++; String temp = st.nextToken(); if (isExits(temp, S[j])) { count++; isFineded = true; System.out.println(i + 1 + " " + count); } else { count++; } } } tempcont = 0; } if (isFineded == false) { System.out.println("Passed"); } } static boolean isExits(String src, String str) { boolean bol=false; if (str.length() > src.length()) { return false; } else if (str.equals(src)) { return true; } else { for (int i = 0; i <= src.length() - str.length(); i++) { if (str.equals(src.substring(i, i + str.length()))) { bol=true; } } return bol; } } } var n,i,k:byte; x,d,y:integer; m:array[0..100] of integer; begin read(n,x); for i:=1 to n do read(m[i]); k:=0; y:=n; if x<0 then begin for i:=1 to y do begin if (m[i]>x) and (m[i]<0) then begin writeln('Impossible'); k:=k+1;end else begin if m[i]<0 then begin y:=abs(x); end; if m[i]>0 then d:=m[i]; end; if m[i]<d then d:=m[i];end; writeln(d+d+abs(x)); writeln(y); end; if x>0 then begin for i:=1 to n do begin if (m[i]<x) and (m[i]>0) then begin writeln('Impossible'); k:=k+1;end else begin if (m[i]>x) and (m[i]>0) then begin d:=x; writeln(d);end; if m[i]<0 then d:=m[i];end; if (m[i]<0) and (m[i]>d) then d:=m[i]; end; writeln(abs(d)+abs(d)+x); end; end. Sorry for Russian... моё решение задачи... перевожу число в двоичную чистему исчисления.. считаю количество единичек.. если это количество четное, то выиграл второй, если нечетное, то первый... Почему такое решение проходит все тесты??? Оно же неверное.. например при N=5 моя прога выдаст, что выиграл второй, хотя на самом деле выигрывает первый, взяв 2 камня... Really... Probably it's another one problem with easy tests. PS: На acm.timus.ru много таких задач, тесты требуют доработки :( Иногда проходят ну очень странные решения :) все правильно выйграет второй, по 1 камню тоже можно брать found my mistake Edited by author 26.06.2012 01:56 i got the same problem! can u plz tell what was your mistake :) I've got AC by stupid brute force, like if (i % 2) k++;. But i think that there is a easier way to solve this task. Topic. но это не тупой брутфорс, просто в четные дни он не ломает предохранители. 100-ый день четный, поэтому ответ 50, а не 51 Seriously, guys, put away correct formulas, please. If ((last day) mod 2 = 0) than formula = ((b - a)+1)/2 else formula = ((b - a) + 2) / 2 I got AC Because if we our seconf day mod = 0, it means, that we mustn't count last day, only add 1. If our second day mod 2 = 1, it means, that we must count second day, add 2. That's easy Edited by author 14.10.2012 16:23 Edited by author 14.10.2012 16:24 input: 3 72 30 50 output: 120.00 But the task is to find the minimal weight! I wonder how 120.00 (2*sqrt(72*50)) can be minimal? It's maximal! Sorry, sample is ok, my thought is not ^^" step #1 : 2*sqrt(72*50) =120 --> colliding 72 and 50 and new stripy with weight 120 step #2 : 2*sqrt(120*30)=120 --> colliding 120 and 30 and new stripy with weight 120 I try to parse digits by symbols this way: using System; using System.Text.RegularExpressions; using System.Globalization; using System.Collections.Generic; //Version 2 namespace CSharpV1 { class Program { //static readonly char[] splitChars = { ' ', '\t', '\n', '\r' }; //Version 1 static void Main(string[] args) { var nfi = NumberFormatInfo.InvariantInfo; //Version 4. Symbolic input int curCharDigit; char curChar; var curDigitString = String.Empty; var rootsStack = new Stack<double>(); while ((curCharDigit = Console.Read()) != -1) { curChar = Convert.ToChar(curCharDigit); if (char.IsDigit(curChar) || curChar == '.' || curChar == ',') { curDigitString += curChar; } else { if (curDigitString.Length != 0) { var curDigit = Convert.ToDouble(curDigitString, nfi); var root = Math.Sqrt(curDigit); rootsStack.Push(root); curDigitString = String.Empty; } } } while (rootsStack.Count != 0) { var curRootString = string.Format(nfi, "{0:F4}", rootsStack.Pop()); Console.WriteLine(curRootString); } rootsStack = null; } } } And I get Wrong answer while test 3... The code works fine with example input data. The digits are Integer. What's wrong? I've got it. I didn't parse the last number when the last symbol is digit. Corrected code: using System; using System.Globalization; using System.Collections.Generic; namespace CSharpV1 { class Program { static readonly NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo; static void Main(string[] args) { //Version 4. Symbolic input int curCharDigit; char curChar; var curDigitString = String.Empty; var rootsStack = new Stack<double>(); while ((curCharDigit = Console.Read()) != -1) { curChar = Convert.ToChar(curCharDigit); if (char.IsDigit(curChar)) { curDigitString += curChar; } else { ParseAndAdd(ref curDigitString, rootsStack); } } ParseAndAdd(ref curDigitString, rootsStack); while (rootsStack.Count != 0) { var curRootString = string.Format(nfi, "{0:F4}", rootsStack.Pop()); Console.WriteLine(curRootString); } rootsStack = null; } static void ParseAndAdd(ref string curDigitString, Stack<double> rootsStack) { if (curDigitString.Length != 0) { var curDigit = Convert.ToDouble(curDigitString, nfi); var root = Math.Sqrt(curDigit); rootsStack.Push(root); curDigitString = String.Empty; } } } } Edited by author 14.10.2012 03:14 I uploaded the following solution but it only says "crash": using System; namespace Week2 { class Program { static void Main(string[] args) { int a, b; a = int.Parse(Console.ReadLine()); b = int.Parse(Console.ReadLine()); Console.WriteLine(a + b); } } } It happens because of you use ReadLine. These digits are on the same line, so you should just split them by space. You can find an example there: http://acm.timus.ru/help.aspx?topic=csharp using System; public class Sum { private static void Main() { string[] tokens = Console.ReadLine().Split(' '); Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1])); } } Edited by author 14.10.2012 01:59Pascal var a,b:real; begin readln(a); readln(b); writeln(a+b); end. Edited by author 10.10.2012 17:42 Edited by author 13.10.2012 20:39 I'm not a Pascal programmer... But... Maybe because these digits are on the same line and you should use "read" instead of "readln"...? Yes, read instead of readln, and also longint instead of real #include <iostream> using namespace std; int main() { int a, c, b, year; double a1, b1, c1; cin >> a >> b >> c; a1=static_cast <double>(a); if(a1<=1024*1024*1024*2-1 && b<=1024*1024*1024*2-1 && c>=1 && c<=100 && a>0 && b>0) { for(year=1; a1=a1*(100-c)/100; year++) { if (a1<=b) { cout << year; break; } } } cin.get(); cin.get(); return 0; }
Please some body tell me why i am gettig wrong answer in this. My code is: #include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <cstring> #include <string.h> #include <cstdlib> #include <sstream> #include <stack> #include <queue> #include <numeric> #include <utility> #include <cctype> #include <list> #include <climits> #include <signal.h> #include <ctime> #include <map> #include <set> using namespace std; #define ll long long int ll i, j, k, ct=0, m, n, t, x, y, z, tc, a[200000],s; vector<ll> ans; int main(){ cin >> n >> s; for(i = 0; i < n; i++){ cin >> a[i]; } sort(a,a+n); for ( i = n-1; i > 0 ; i-- ) { if ( a[i] + a[i-1] <= s ) { break; } } // cout << x << " " << y << endl; if(s%2==0){ x = i+1; y = i; //z = n-1; while ( x < n && y >= 0 ) { ans.push_back( a[y] ); ans.push_back( a[x] ); x++; y--; } while ( x < n ) { ans.push_back( a[x] ); x++; } while ( y >= 0 ) { ans.push_back( a[y] ); y--; } } else { y = i; while ( i < n && a[i] == a[y]){ ans.push_back( a[i] ); i++; } y--; x = i; while ( x < n && y >= 0 ) { ans.push_back( a[x] ); ans.push_back( a[y] ); x++; y--; } while ( x < n ) { ans.push_back( a[x] ); x++; } while ( y >= 0 ) { ans.push_back( a[y] ); y--; } } ct = 0; for ( i = 0; i < ans.size(); ) { if( i == ans.size() - 1){ ct++; i++; } else{ if( ans[i] + ans[i+1] <= s){ ct++; i+=2; } else{ ct++; i++; } } } cout << ct << endl; for ( i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } return 0; } Edited by author 13.10.2012 20:42 My god! When I use gcc I get the right anwer, but vc++2010 doesn't. What should I do? There is still time left in the competition...? I have a problem with test 2 too Edited by author 14.10.2012 00:59 сам ни до конца понял я условие понял, но ва6. Edited by author 14.10.2012 00:59 числа из отрезка подходят под нормальный сигнал! Edited by author 14.10.2012 00:59 I solved this problem on Pascal and was AC. But i wrote same program on C and C++. It gives same answers on same tests on my machine but gives WA on test 1 when i submit. These my programs: On pascal:: var a:array[1..10000] of integer; k,n,m,i:integer; s:longint; procedure cle; var i:integer; begin for i:=1 to n do a[i]:=0; end; begin read(n,m); cle; s:=0; for i:=1 to m do begin readln(k); if k<>0 then inc(a[k]); end; for i:=1 to n do begin if a[i]<>0 then writeln(a[i]/m*100:2:2,'%') else writeln('0.00%'); end; end. On C: #include <stdio.h> void main(){ int k,n,m,i; int a[10000]; scanf("%d %d\n",&n,&m); for (i=1;i<=n;i++) a[i]=0; for (i=1;i<=m;++i){ scanf("%d",&k); if (k!=0) a[k]++; } for (i=1;i<=n;++i){ if (a[i]!=0) printf("%2.2f%\n",(float)a[i]/m*100); else printf("0.00\n"); } } 1) Use "double" instead of "float". 2) Don't use Pascal, 'cause C++ is really cool language. P.S. I don't understand how can people write theese "begin ... end" so many times? I don't understand people who think they are cool enough to speak such foolish things ;) Pascal is not worse than C++, and it is up to one to choose what language to use - as for me I use Pascal and I am in Top 10 :) Safe Bird uses C++ - but he does not scream that C++ is better... P.S. Sorry, can not control myself when Pascal in under attack ;) RESPECT++++++ PASCAL RULEZZZ!!!! Hmm... Pascal is not spported at World Finals now. Best programmers have started using Java. Maybe Timus must do the same - substitute Pascal to Java. Don't you want to double all timelimits for "fast" Java programs to pass them? :))) oooh. Yesss. Java is good. I will glad if timus add Java compiler to this contest "Pascal is not spported at World Finals now" - с этого года что ли? Pascal provided but not supported read this: http://icpc.baylor.edu/systems/finals/pascal.htm Pascal will not be removed from Timus of course. Java will be added as soon as possible, but not to February, 11. It is possible to recalculate all timelimits for Java. But it is impossible to make all problems solvable in Java. Edited by author 04.02.2006 15:05Tolstobrov Anatoliy[Ivanovo SPU] :) [1] // Задача 1263. Выборы 4 фев 2006 18:58 deleted Edited by author 26.10.2018 14:38 deleted Edited by author 26.10.2018 14:37 Vedernikoff 'Goryinyich' Sergey (HSE: АОП) Re: +++ [1] // Задача 1263. Выборы 16 фев 2009 03:38 And why it is problem to solve it in Java? What we need for solution - just one array int[1000] But I really don't understand why timelimit is so small - memory is not crucial part of this problem at all... memory is not crucial part of this problem at all... Maybe author wanted to cut off DP way of solving this problem or something like this. I did't say that Pascal is bad, nasty, ugly, damned language or something like it. But... U must agree with me that up to now there is no compiler for Pascal that can be compared with MVC++ or g++. Theese make really good machine code. :) And IMHO this language is uncomfortable to write algorithms and serious projects. What for Top 10... over some year Top 10 or even Top 50 can became consisting only of Pascal (or - that's terrible - Java) users. Even BASIC coders could be cool because they ARE cool. You think we prefer language? Often programming language prefers us. Pascal is popular in Russia just because of traditions begun with 80's. P.S. I accept your apology, but "LOL" is offensive, don't you think? ДИМАН VERY GOOD MAN, НАПИСАЛ LOL, НАПИШИ ЕМУ ТАКЖЕ:) I suggest to make a voting. I use pascal about 5 years for solving problems. And as for me, I think that pascal is not so uncomfortable to write algorithms. Edited by author 07.02.2006 21:39 Hi! I'm first time here and seems the last - cause there is no Java support. Are you going to add it soon? Pascal is the worst language I ever seen..... Shut up! Pascal Will Newer Die! Edited by author 18.10.2006 08:05 In C++ very hard syntax, and Pascal is good language too Currently I'm using C++ for solving problems, but can say: Pascal foreva! C++ has many drawbacks which are worse than just long "begin .. end" I solved problems using all languages available on this server and Java seems to be most convenient for me.. #include <iostream> #include <stdio.h> using namespace std; int main() { int br[10024],i,m; double n,a; float sum; cin>>n>>a; sum=100/a; for(i=1;i<=10024;i++) { br[i]=0; } for(i=1;i<=a;i++) { cin>>m; br[m]++; } for(i=1;i<=n;i++) {
printf("%.2lf",(br[i]*sum)); cout<<"%"<<endl; } return 0; } 1) Look how your C++ program will work with n=10000;) 2) You've forgotten about percent sign in else printf("0.00\n"); 3) Don't use % in printf, use %% (it will show as %) 4) LEARN C++ well before writing on it! Edited by author 03.02.2006 17:57 >> 2) You've forgotten about percent sign in else printf("0.00\n"); Is it really necessary? Can anyone translate my solution below into C++? I want to learn programming in C/C++ too :) type TArray=array of dword; var arr:TArray; m,n,c,i:dword; begin readln(n,m); setlength(arr,n+1); for i:=1 to n do arr[i]:=0; for i:=1 to m do begin readln(c); arr[c]+=1; end; for i:=1 to n do begin writeln((arr[i]*100/m):2:2,'%'); end; end. |
|