|
|
Common BoardI had a small bug in my code. I found it using my test sample. I would like to share it with you. I have used some extra white space in the boolean expression. I am not sure if it is necessary, you can remove them. Input: (NOT ( (NOT NOT TRUE ) AND A) OR (B AND C AND D)) OR E 3 10 14 -3 -3 -3 -1 -3 3 -1 1 0 -2 2 -1 2 3 3 -3 3 0 3 2 -3 -2 A -2 -3 A -2 -1 A -1 -3 D -1 -1 Z 0 -3 C 0 -1 C 1 -3 E 1 0 A 2 -3 B 2 0 A 2 1 E 3 -1 E 3 3 B 0 0 1 0 2 0 3 0 3 1 3 2 2 2 1 2 0 2 -1 2 -2 2 -3 2 Output: 0 0 1 0 2 0 3 0 3 -1 3 -2 3 -3 2 -3 1 -3 0 -3 -1 -3 -2 -3 -3 -3 -3 -2 -3 -1 -2 -1 -1 -1 0 -1 1 -1 2 -1 2 0 2 1 2 2 2 3 3 3 This is how the table looks like: (1 means there is a Fork and * means empty cell) 1 A 1 * * * 1 A * A * * * * D * Z * 1 * * C 1 C * * * * E * * A * * * B * 1 A E * 1 1 * E 1 * 1 B del Edited by author 06.01.2015 21:37 Solution in Go. I was getting WA#4 and then changed my input matrix from [][]int8 to [][]int16 and the solution was accepted. Edited by author 21.12.2014 14:38 Who can tell me? Thanks! tests: 4 AAaaaaAA output data: (case 1)2 3 1 4 (case 2)3 2 4 1 (case 3)1 2 3 4 (case 4)4 3 2 1 Which is the correct answer? Edited by author 29.11.2014 18:43 Correct answer for this test is 2 1 4 3 RT @Nodir NAZAROV [TUIT-Karshi] Thanks a lot! AC now! Correct answer for this test is 2 1 4 3 consider line breaks between inputs del Edited by author 06.01.2015 21:37 5 ta satrli 3 ta ustinli listdan nechta kerak. 5 3 6 To be or not to be javob: 2 English please translate: for this testcase correct answer is 2. 5 3 6 To be or not to be del Edited by author 06.01.2015 21:38 THIS IS ACCEPTED CODE // *CoDeD by Ye.A # include <iostream> # include <cstdlib> # include <cstdio> # include <vector> # include <algorithm> using namespace std; const int N = 222; vector <int> g[N], ans; int n; bool used[N]; int main () { //freopen ("input.txt", "r", stdin); //freopen ("output.txt", "w", stdout); scanf ("%d", &n); for (int i = 1; i <= n; i++) while (1) { int x; scanf ("%d", &x); if (!x) break; g[x].push_back (i); }
while (ans.size() != n) for (int i = 1; i <= n; i++) if (!used[i] && g[i].empty()) { ans.push_back (i); used[i] = true; for (int j = 1; j <= n; j++) if (binary_search(g[j].begin(), g[j].end(), i)) g[j].erase (lower_bound(g[j].begin(), g[j].end(), i)); }
for (int i = 0; i < n; i++) printf ("%d ", ans[i]);
return 0; } Here is the code(c++), what is wrong? #include <iostream> #include <string> using namespace std; int main() { string name[1001]; int counter=0; int n,i=0; cin>>n; while(i<=n) { getline(cin,name[i]); if(i!=0) if(name[i-1][0]!=name[i][0]) if(name[i-1][0] == 'A' || name[i-1][0] == 'P'||name[i-1][0] == 'O'||name[i-1][0] == 'R') { if(name[i][0] == 'B' || name[i][0] == 'M'||name[i][0] == 'S') counter++; else counter+=2; } else if(name[i-1][0] == 'B' || name[i-1][0] == 'M'||name[i-1][0] == 'S') { counter++; } else if(name[i-1][0] == 'D' || name[i-1][0] == 'G'||name[i-1][0] == 'J'||name[i-1][0] == 'K'||name[i-1][0] == 'T'||name[i-1][0] == 'W') { if(name[i][0] == 'B' || name[i][0] == 'M'||name[i][0] == 'S') counter++; else counter+=2; } i++; } cout<<counter; } Use a map instead of many "if"s. Can someone give me test cases? I believe my solution works and tried with many possible inputs and I get the right result. I found that it is possible to have more than one input value on the same line. And now I fail to pass #5. Any test cases would be much appreciated. Edited by author 20.12.2014 13:42 import java.io.*; import java.util.*; public class TokenExplain { public static void main(String[] args) throws IOException { //this program gets two tokens on a single line and calculates their sum StreamTokenizer in =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); in.nextToken(); int a=(int)in.nval; in.nextToken(); int b=(int) in.nval; System.out.println(a+b); }
} As you can see, it was well written, but when it was compiled, it took 0.078 seconds while i see fellow java coders clocking speed of 0.031, can you suggesting better classes to read inputs instead of the one i used, all other suggestions are highly welcome It has no problem and can be accepted. Yes, it was accepted but that is not the issue. The real issue is how i can optimize the code in such a way to clock 0.031 sec that others clocked. Thanks. But I cant find the code which clock 0.031 by google. Can anyone help me? deleted: Edited by author 24.12.2014 23:56 What is test 4, there is a question about it but I don't understand the answer. All the eigenvalues are positive integers not exceeding 10^9. Does it mean they are non-zeros? My solution assumes there are not zeros, maybe that's the cause of WA. And why do I get compilation error using Visual C 2010? It's ignoring semicolons. Sorry for this topic, I just initialized array to -1 instead of zero, and tested against it. #include <iostream> using namespace std; int main() { int a=1, b=5, sum=0; sum=a+b; cout<<sum<<endl; return 0; } Ты вводишь два числа, а не определяешь в коде. А система проверки может дать тебе любые два числа, не обязательно a=1 и b=5 ты должен ввести входные данные выводные данные Time limit exceeded Test №3 С# using System; public class Test { private static void Main() { ushort n = ushort.Parse(Console.ReadLine()); string result = ""; int t; for (ushort i = 0; i < n; i++) { t = int.Parse(Console.ReadLine()); if (Math.Sqrt((8 * t) - 7) % 1 == 0) result += " 1"; else result += " 0"; } Console.WriteLine("{0}", result); } } Whats wrong? [code deleted] Edited by moderator 19.11.2019 22:49 [code deleted] Edited by moderator 19.11.2019 22:50 [code deleted] Edited by author 07.10.2014 17:38 Edited by moderator 19.11.2019 22:50 [code deleted] Edited by moderator 19.11.2019 22:50 Try test 3 1 10 2 20 2 30 Edited by author 20.03.2007 21:45 |
|
|