Common Board#include<iostream> using namespace std; int GCD( int a, int b ) { a = abs( a ); b = abs( b ); while ( b ) { int tmp = a % b; a = b; b = tmp; } return ( a ); } int main() { int s=0,n,i; cin>>n; for(i=1;i<=n/2;i++) if(GCD(n,i)%n==1) s++; cout<<s; system("pause"); return 0; } can't believe somebody used system("pause"); Should'nt this code be deleted by the admins? Edited by author 12.02.2014 02:34 If you have WA#7 check that your program works correct with strings with symbols "{" and "//" #include <iostream> using namespace std; int main() { int k,a[1001],i(0),s(0),maxs(0),j(0); cin >> k; while(i<k) { cin >> a[i]; i++; } for (i=0; i<k; i++){ if (a[i]==a[i+1] && a[i]==a[i+2]) { s = a[i]*3; j = i+2; } if (s > maxs) { maxs = s; s = 0; } } cout<<maxs<<"\n"<<j<<endl; } Edited by author 10.02.2014 22:44 why??? #include <iostream> //#include <stdlib.h> //#include <stdio.h> #include <string.h> using namespace std; int i,o,tp,nm; struct Tpart { int val [24]; int k; Tpart *lst;
}; char com[100]; Tpart stk[1024]; int Pop(Tpart *p) { if(p->k>0) return p->val[--(p->k)]; else { Tpart *e=p; p=p->lst; delete e; return p->val[--(p->k)]; }}; void Push(Tpart *p, int val) { if((p->k)<24) (p->val)[(p->k)++]=val; else { Tpart *uk= new Tpart; uk->lst=p; p=uk; p->k=0; (p->val)[(p->k)++]=val; } return; } int main() { int n; cin>>n; for(int j=0;j<n;j++) { cin>>com; if (strcmp(com,"PUSH")==0) { cin>>nm>>tp; Push(&stk[nm-1],tp); } if (strcmp(com,"POP")==0) { cin>>nm; cout<<Pop(&stk[nm-1])<<endl;} } return 0; } Just give me some hint pls: intueor19@gmail.com I really don't understand what is wrong... It passes all tests on that forum but still has WA15 #include <iostream> #include <vector> using namespace std; vector < int > pm (30, 0); vector < vector < char > > d (31, vector < char > (1000000, 0)); int n; void printAnswer (int, int); int main () { cin >> n; pm[0] = 1 % n; for (int i = 1; i < 30; ++i) pm[i] = (pm[i - 1] * (10 % n)) % n; d[0][0] = 1; char found = 0; for (int i = 1; i <= 30; ++i) { int m1 = pm[i - 1]; int m2 = ((2 % n) * pm[i - 1]) % n; if (d[i - 1][(n - m1) % n] != 0) { printAnswer (1, i); found = 1; break; } if (d[i - 1][(n - m2) % n] != 0) { printAnswer (2, i); found = 1; break; } for (int j = 0; j < n; ++j) { if (d[i - 1][j] == 0) continue; d[i][(j + m2) % n] = 2; d[i][(j + m1) % n] = 1; } } if (!found) cout << "Impossible"; return 0; } void printAnswer (int digit, int lvl) { int k = 0; int x, j; while (lvl != 0) { cout << (int)digit; j = ((digit % n) * pm[lvl - 1]) % n; x = (k >= j) ? (k - j) : (n - j + k); digit = d[lvl - 1][x]; k = x; --lvl; }
return; } I got AC with other code but I still don't understand what's wrong with this one. Help me PLS!!! Edited by author 09.02.2014 19:37 Could you tell me some useful test, if you had the same problem?! Thanks ^_^ can you tell me test 35? i have WA The answer for "30 1 2012": mon........2....9...16...23..[30] tue........3...10...17...24...31 wed........4...11...18...25..... thu........5...12...19...26..... fri........6...13...20...27..... sat........7...14...21...28..... sun...1....8...15...22...29..... between first and second column there are exactly 4(!) '.'; Considering my submissions, I concluded that in the 15-th test there is a radiobeacon for which its coordinates can't be integers between 1 and 200. If for such radiobeacons output "UNKNOWN", the solution gets AC. This does not fit with the statement. I didn't use any long arithmethic but i think it should passes the first test. But judge says WA !!! Help please if you can #include <iostream> using namespace std; long long d[10001][2]; int main () { int n, k;
cin >> n >> k;
d[0][0] = 1; d[0][1] = 0;
int i, j;
for (i = 1; i <= n; ++i) {
d[i][1] = 0; for (j = 1; j <= k; ++j) { if (n - j < 0) continue;
d[i][1] += d[i - j][0]; }
d[i][0] = d[i - 1][0] + d[i - 1][1]; }
cout << d[n][0] + d[n][1];
return 0; } I've solved it using bruteforce for small K and then guessing the formula. But I still don't know the proof. Can anybody write it? S(A + B) = S(A) + S(B) is equal to that that for every pair of corresponding digits of A and B their sum is lower then 10 (1). For example: 12 and 13 :1+1<10;2+3<10 it means S(A + B) = S(A) + S(B) 18 and 19: 8+9>10 it means S(A + B) = S(A) + S(B) is wrong here. Then for every pair of digits from A and B you just count how many varints of pair suits (1) and multiply these quantities for all pairs. thanks Another way to go at it is to think of the number (A+B) as a bunch of stacked blocks, each stack representing a digit. Here is 43 for example: _ |_| _ |_||_| |_||_| |_||_| Now, to find all the A's and B's that can form S(A+B) = S(43), for example 12+31 or 22+21, etc, we can represent this as chopping each stack into two parts, for example in the case of 12+31: _ |_| _ _ |_| |_||_| |_| _ |_||_| Now, if we take the general case of having two digits, if the first digit is 1, we can't split the first digit in two since the first digit of A or B can't be 0. However, if the first digit is 2, we can split it in one way (in the middle), and then we can split the second digit depending on what digit it is. If it is 2, we can split it in 3 different ways ( (0,2),(1,1),(2,0) ). If it is 3, we can split it in 4 different ways, etc. So, if the first digit of the two-digit number is 2, we can split the whole number in 1*(1+2+3+4+5+6+7+8+9+10)=1+(10*11/2) different ways. If the first digit is 3, we can split the whole number in 2*(1+2+3+4+5+6+7+8+9+10)=2*(10*11/2) different ways, etc. If we sum everything we get (8*9)/2*(10*11)/2 ways to split a two digit number. For an n digit number continuing the same way we get (8*9)/2*((10*11)/2)^(n-1). 1) "after every fall, the kinetic energy of the ball decreases by a factor of K". So if K > 1, that means the energy becomes negative? E_2 = E_1 - E_1*K might be interpreted to be what you mean when you say something decreases by some factor. 2) "Your task is to determine the maximal distance from the point of throwing that the ball can fly." If the ball is pitched straight up, it will fly some maximal distance from the point of throwing before it reaches the ground again. You should probably exactly what you mean. I'm newby here and I didn't solve this kind of tasks before. I know, that must be very easy, give me please some pieces of advice to solve it. Think abstractly! It's very easy! Edited by author 06.02.2014 05:58 Edited by author 06.02.2014 05:58 You can either take it the mathematical way, and solve it by induction: assume you know the number of ways for 1..N stripes, how to find out the ways for N+1? Or you can make a brute-force algorithm (backtracking) that simply counts and prints the number of ways for each N between 1 and 10-20 (until it gets too slow), then try to deduce a general rule for N, based on this series. Good luck! Hey, guys, it is not serious, really ...... I had wa4 with EPS = 1e-8 .... when I've changed EPS = 1e-6 I got AC... Edited by author 06.02.2014 18:13 Does anyone know what's this test like? using System; namespace ConsoleApplication4 { class Program { static void SQRT(UInt64 sum) { double ima_ans = Convert.ToDouble(Math.Sqrt(Convert.ToDouble(sum))); Console.WriteLine(Convert.ToDouble((Math.Round(ima_ans = ima_ans * 10000)) / 10000)); } static void Main(string[] args) { string save_str=null; string str = Console.ReadLine(); int i = str.Length; int k; UInt64 sum; i = i - 1; while (i >= 0) { k = 0; while (i >= 0 && str[i] != ' ') { k = 1; save_str += str[i]; i = i - 1; } sum = Convert.ToUInt64(save_str); if (sum > 0 && sum <= Math.Pow(10, 18) || k == 1) SQRT(sum); save_str = null; i = i - 1; } Console.ReadLine(); } } } Don't have any idea, give me that or similar test please. #include <iostream> using namespace std; int main() { int a,b; cin>>a; if(a==0 && a<=10000) cout<<"1"; else { if(a>0 && a<=10000) cout<<((a*(a+1))/2); else { if(a<=10000){ b=-((((-a)*((-a)+1))/2)-1); cout<<(b);} else cout<<"error";} } return 0; } Edited by author 05.02.2014 01:45 Ok, just search biggest prime number :) Edited by author 04.02.2014 22:13 more than one registrations ;) |
|