Common BoardIsn't Test#5 the n=500 one? n = 2 the answer is 2 , isn't it? Try this: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 -3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 White c6-d7 Incorrect 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 -3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 I had WA9 because i thought there would be only one king of the same color, but seems like actually there might be more. Thankfully to take more kings into account i had to delete some of my code rather than add some. An example test: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 6 0 6 0 0 0 0 0 1 White <any move> (for example a1-a2 or c1-c2) The answer is "Incorrect" and then a table, because no matter what white does, there's at least one king remaining under check. Also had WA7 because of using shortint and a bit too small constant for amount of available moves. After changing from 100 to 300 and from shortint to longint got AC. An example test, where white have 288 available moves: 5 5 5 5 5 5 5 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 5 5 5 5 5 5 5 1 White a1-b2 Result: "Draw" and table output. Edited by author 11.01.2016 03:55 use cin.eof() to judge the end of input and get WA 3; scanf get AC and while(cin >> a) may case Time Out why does cin.eof() produces WA 3 ? You should use while(scanf("%lf", &a)) #include<iostream> #include<math.h> int main() { using namespace std; int i; float r,a[128*64]; unsigned long long n,j,k; for(i=0;i<n;i++) cin>>a[i]; j=n-1; for(k=j;k>=0;k--) { r=sqrt(a[k]); cout<<r<<"\n"; } return 0; } You should try to increase the size of your array and perhaps use a double array over float. > A size of the input stream does not exceed 256 KB Minimum number of chars per number is 2 - "0 ". So you have to receive up to 128 K numbers. Your array is about 8 K numbers. You shouldn't allocate such big arrays on stack. Use dynamic allocation or std::vector. And another note. > unsigned long long n,j,k; > for(i=0;i<n;i++) > cin>>a[i]; How many times will this for iterate? Why? Edited by author 15.12.2015 21:02 It's preferable to use a double precision floating point type over a single float. n is not given in the input data. I recommend to use std::vector to alloc it: vector <double> input; double aux; while(cin>>aux) input.push_back(aux); Edited by author 10.01.2016 23:58 input: 7 1 1000 2 500 501 999 3 499 502 800 4 400 503 700 output: 4 6 4 2 1 or 4 7 5 3 1 Chto za xren Test 5? Does anybody know what the hell is Test 5? Check if you comparing right prices for 2-rooms apartment when person lives single. #include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX 16500 void prime(int n) { int i,j,temp,count=0; for(i=2;i<=MAX;i++) { temp=0; for(j=2;j*j<=i;j++) { if(i%j==0) { temp=1; break; } } if(temp==0) { count++; } if(count==n) { printf("%d\n",i); break; } } } int main() { int n,t,i; scanf("%d",&t); while(t--) { scanf("%d",&n); prime(n); } return 0; } Why i got this TLE. I think my idea is not wrong but why its occur? I don't understand. Pleas help me..... Edited by author 06.09.2015 20:29 Your algorithm is not wrong, but it cost too much time. Try "sieve of Eratosthenes". You can search it on wiki. Правильное решение (Accepted): using System; namespace _1086_Криптография { class Program {
static void Main(string[] args) { // считываем количество выводимых чисел int n = int.Parse(Console.ReadLine()); // создаем массив и считуем в него порядочные номера простых чисел int[] hip = new int[n]; for (int i = 0; i < n; i++) { hip[i] = int.Parse(Console.ReadLine());
} // определим максимальный элемент масива // можно исользовать цикл int[] hip1 = new int[n]; Array.Copy(hip, hip1, n); Array.Sort(hip1); // зададим массив упорядоченых простых чисео с запасом int[] val = new int[hip1[hip1.Length - 1]+2]; // зададим начальный ряд простых чисел val[0] = 2; val[1] = 3; val[2] = 5; val[3] = 7; // определяем простые числа делением на предыдущие простые числа // метод итераций построен на do while int k = 4; int i1 = 8; do { int reid = 0; for (int i = 0; i < k; i++) { if (i1 % val[i] == 0) {reid = 1; break; } } if (reid == 0) { val[k] = i1; k++; } i1++;
} while (k < hip1[hip1.Length - 1]+1); // вывод заданых простых чисел for (int i = 0; i < hip.Length; i++) { Console.WriteLine(val[hip[i]-1]); } } } } Edited by author 08.01.2016 17:23 Edited by author 08.01.2016 17:23 i have WA #2 #include <iostream> #include <stdio.h> using namespace std; int main() { int n, m; cin >> n >> m; int win = 0; for(int i = 0; i < m; i++) { int a; cin >> a; n -= a; if(i % 2 == 0) win = 2; else win = 1; }
cout << win << endl;
return 0; } First of all. If you get WA#1, check how you scan input stream, cause they've put some trash in file. I used the following idea. The whole number with base k divisible by ( k - 1 ), if sum( div( digit[ i ] ) ) is divisible by ( k - 1 ). Where digit[ i ] is k-based digit in input number ( char from input stream ); div( digit[ i ] ) is a remainder of division digit[ i ] * k by ( k - 1 ). Let see digit on i-th position, for example, it's A. So in decimal implementation it's equal to A * k ^ i. A * k ^ i = A * k^i - A * k^(i-1) + A * k^(i-1) = A * k^(i-1) * ( k - 1 ) + A * k^(i-1) A * k^(i-1) * ( k - 1 ) is divisible by ( k - 1 ), so we have to check only A * k^(i-1). If we repeat the same logic to this expression (i - 2) times, we see, that we have to check division A * k / ( k - 1 ). I tried my best to explain the main idea, sorry if it can't be understood. You don't need your "div()". Isn't it okay to just find the digital sum of the given number and add 1? Thank you. And we even can go a step further. Now see, A * k = A * k - A + A = A(k - 1) + A, So what we need to examine is just whether sum( digit[i]) is divisible by ( k - 1). input1 sd5=#124'ashds'#12#154'sah'; input 2 sd5:=#123+#12; output1: sd5=<span class=string>#124</span><span class=string>'ashds'</span><span class=string>#12</span><span class=string>#154</span><span class=string>'sah'</span>; I got WA1 and I don't understand why. Give me some tests please. Test #1 describe into problem statement. 10 3 3 4 5 1 What it means, we have range [0, 10] and start position in 3. And have 3 shifts. First shift we can go from 3 to [-1, 7] as -1 not in range we have only [7] positions. Second shift we can go to positions [2, 12] as 12 not in range we have only [2] position. Third shift we can go to positions [1, 3] as all of them in range we have 2 possible final states 1 and 3, minimal of them 1 and maximal 3. Answer will be 1 3. Another test: 100 50 4 1 2 4 8 Possible positions on steps: 0) [50] 1) [49, 51] 2) [47, 49, 51, 53] 3) [43, 45, 47, 49, 51, 53, 55, 57] 4) [35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65] Answer will be 35 65 What does it mean: "clockwise order"? How do you define clockwise order in notconvex polygon? For example: in picture like a snail what roundabout way is turned in the clockwise direction and what is not? Sorry for bad Enlish... Hi. Can you remember, what was the problem with test 14? how could it have been passed??? and with 0.031 because of the test cases are to easy.... you can use (next_permutation) easyly... Can anyone give me some tricky tests? 5 RGRBG 7 RBGBRGB 6 RGBGRB 4 RRBG Can I get some test inputs please? Input: 1 1 2 Output: -2 why? Because 1-1-2=-2 But in problem description "You are not allowed to use unary minus and parentheses in the expression", so 1-1-2 is not correct Edited by author 21.10.2015 16:37 Unary minus and usual minus are different things... [code deleted] Edited by moderator 24.11.2019 13:46 5 2 1 answer: 5-2-1 = 2 your program would say 3 For 5 2 1, it's -9. Numbers can be placed in any order. input numbers are nondecressing order so you can't put 5 2 1 |
|