| Show all threads Hide all threads Show all messages Hide all messages |
| I get accept,but i don't why | aurora | 1110. Power | 6 Sep 2016 13:17 | 2 |
#include<iostream> using namespace std; int main() { int N, M, Y; while (cin >> N >> M >> Y) { int f = 0,t=-1; for (int i = 0; i < M; i++) { int x = i; long long y = x; for (int j = 2; j < N + 1; j++) { y *= x; y %= M; } if (y== Y) { if (f > 0) cout << ' '; cout << x ; f ++; } } if (f == 0) cout << t; cout << endl; } return 0; } why it can get accept,but this one get WA #include<iostream> using namespace std; int main() { int N, M, Y; while (cin >> N >> M >> Y) { int f = 0,t=-1; for (int i = 0; i < M; i++) { int x = i; long long y = x; for (int j = 2; j < N + 1; j++) { y *= x; } if (y%M== Y) { if (f > 0) cout << ' '; cout << x ; f ++; } } if (f == 0) cout << t; cout << endl; } return 0; } Your second program assumes that all x^N are less than long long limit. It isn't true. 10^999 requires about 999 digits. long long limit is about 19 digits. |
| Why is there always COMPILATION ERROR? It was compiled successfully in my local IDE. | TanyaLew | 1001. Reverse Root | 6 Sep 2016 13:10 | 3 |
I have a hard time submitting my first piece of code. Compilation error appeared and I have no idea why. The following is my code. import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * Created by Tanya on 2016/9/5. */ public class ReverseRoot2 { Scanner in; PrintWriter out; public void work()throws Exception { List<Double> numlist = new ArrayList<Double>(); in = new Scanner(System.in); String line = ""; while(in.hasNextLine() && !(line = in.nextLine()).equals("")) { String[] strnums = line.split(" "); for(String strnum : strnums) { if(strnum.matches("[0-9]+\\.*[0-9]*")) { numlist.add(Double.parseDouble(strnum)); } } } out = new PrintWriter(System.out); int len = numlist.size(); for(int i = len - 1;i>=0;i--) { out.print(Math.sqrt(numlist.get(i).doubleValue()) + "\t"); } out.flush(); } static public void main(String[] args)throws Exception { ReverseRoot2 rr = new ReverseRoot2(); rr.work(); } } After you submit your code, if it gets "compilation error", within the next 15 minutes it is underlined — you can click on it and see the error message. |
| Help me please with this task! C | Igorabc1 | 1493. One Step from Happiness | 6 Sep 2016 00:23 | 2 |
my code: #include <stdio.h> #include <math.h> #include <string.h> #include <conio.h> int SL (int n) { int q=n/1000, i, s=0; while (q>10) { s+=q%10; q/=10; } s+=q; return s; } int SR (int n) { int s=0,q=n%1000; while (q>10) { s+=q%10; q/=10; } s+=q; return s; } void main() { int S=0,T=0,N; scanf ("%d", &N); if ((SR(N+1)==SL(N+1))||(SR(N-1)==SL(N-1))) printf ("Yes"); else printf ("No"); } I remaked a bit your programm and it got acceped. What you need to change is SL and SR functions: int SL(int n){ int q=n/1000, i, s=0; while(q!=0){ s+=q%10; q/=10; }
return s; } int SR (int n){ int s=0, q=n%1000; while (q!=0) { s+=q%10; q/=10; }
return s; } Thanks for your code, i didn't need to write that myself :) |
| why i get Runtime error (access violation) | Davidfeng | 1001. Reverse Root | 4 Sep 2016 22:14 | 2 |
#include<iostream> #include<cmath> #include<iomanip> using namespace std; int main() { long long a[100000] = {0}; int i = 0; while (cin >> a[i]) { i++; } for (int j = i-1; j >= 0; j--) { cout << fixed << setprecision(4) << sqrt(a[j]) << endl; } } How did you think "100,000" is enough for the input? You shouldn't allocate big arrays on stack. You should allocate big array in heap or use vector. |
| getting Runtime error in test case 3 of metro. Please help | Sushant Bhat | 1119. Metro | 4 Sep 2016 19:34 | 2 |
#include<iostream> #include <cmath> #include <climits> #include <deque> using namespace std; int v[1001][1001]; float table[1002][1002]; int metro(int n,int m,int k){ deque<int> qi,qj; qi.push_back(1); qj.push_back(1); table[1][1] = 0; while(!qi.empty()){ int i = qi.front(),j = qj.front(); qi.pop_front(); qj.pop_front(); if(i <= n && table[i+1][j] > table[i][j]+100){ qi.push_back(i+1); qj.push_back(j); table[i+1][j] = table[i][j]+100; } if(j <= m && table[i][j+1] > table[i][j]+100){ qi.push_back(i); qj.push_back(j+1); table[i][j+1] = table[i][j]+100; } if(v[i][j] == 1){ if(i <= n && j <= m && table[i+1][j+1] > table[i][j] + 141.4){ qi.push_back(i+1); qj.push_back(j+1); table[i+1][j+1] = table[i][j]+(141.4); } } } return ceil(table[n+1][m+1]); } int main(){ int n = 0,m = 0,k = 0; cin>>n>>m; for(int i = 0;i <= n+1;++i){ for(int j = 0;j <= m+1;++j){ v[i][j] = 0; table[i][j] = INT_MAX; } } cin>>k; for(int i = 0;i < k;++i){ int x = 0,y = 0; cin>>x>>y; v[x][y] = 1; } cout<<metro(n,m,k)<<endl; return 0; } Edited by author 29.08.2016 16:40 Edited by author 29.08.2016 16:40 It is a biggest test for check boundaries. And you are have a problems with it. For example: for(int i = 0;i <= n+1;++i){ for(int j = 0;j <= m+1;++j){ v[i][j] = 0; where v is: int v[1001][1001]; With n = 1000 this code will crash. It's about 3 test case. Ans I see another mistakes... |
| Что не так? | Shtek97 | 1001. Reverse Root | 3 Sep 2016 22:47 | 1 |
Program Pr1; var i:longint; A:real; k,n:longint; begin readln(n,k); for i:= n downto k do begin A:=sqrt(i); writeln(A:0:4) end; end. |
| WA #85 | AsgarJavadov | 2070. Interesting Numbers | 1 Sep 2016 22:09 | 1 |
WA #85 AsgarJavadov 1 Sep 2016 22:09 What is the test #85 ? Edited by author 01.09.2016 22:25 |
| What is test 1? I always have runtime error | __Andrewy__ | 1980. Road to Investor | 1 Sep 2016 20:44 | 3 |
Короче, баг был в коде for (int i = 1; i <= nmax; i++) adress[i] = NULL; - знак должен быть СТРОГИЙ! Edited by author 26.08.2016 20:54 will the overspeeding value always lie between 0 to 300 ? No. Test: 2 1 1 2 1 1000 1 Ans: 999.000000 1 1 HINT: overspeeding value is max when s->min,l->min,t->min, path->max Edited by author 01.09.2016 20:45 |
| What is test case 21 about? | szawinis | 2030. Awesome Backup System | 1 Sep 2016 20:02 | 1 |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9+7, BLOCK = 320; int n, m, a[100001], p[100001], idx[100001], order[100001], lb[100001], rb[100001]; // lb and rb are indexed by bfs order, not vertex bool mark[100001]; vector<int> g[100001]; struct coolsqrt { // sqrt decomposition int f[100001], t[100001]; void init() { for(int i = 1; i <= n; i++) f[i] = a[order[i]]; } void update(int l, int r, int v) { for(int i = l; i % BLOCK; i++) { f[i] = (f[i]+v)%MOD; if(i == r) return; } int block = l/BLOCK + 1; while(block < r/BLOCK) t[block++] += v, t[block] %= MOD; for(int i = BLOCK*(r/BLOCK); i <= r; i++) f[i] = (f[i]+v)%MOD; } int query(int i) { return (f[i] + t[i/BLOCK])%MOD; } void putin() { for(int i = 1; i <= n; i++) cout << query(i) << ' '; cout << endl; } } coolsqrt; int main() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1,u,v; i < n; i++) { cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } queue<int> q; q.push(1); for(int i = 1, u = q.front(); i <= n; i++, q.pop(), u = q.front()) { mark[u] = true; idx[u] = i; order[i] = u; for(int v: g[u]) if(!mark[v]) q.push(v), p[v] = u; } assert(q.empty()); for(int i = 1; i <= n; i++) if(p[order[i]]) { if(!lb[p[order[i]]]) lb[p[order[i]]] = i; rb[p[order[i]]] = i; } coolsqrt.init(); cin >> m; int inst,v; while(m--) { cin >> inst >> v; if(inst == 1) { coolsqrt.update(idx[p[v]], idx[p[v]], coolsqrt.query(idx[v])); coolsqrt.update(lb[v], rb[v], coolsqrt.query(idx[v])); // coolsqrt.putin(); } else { cout << coolsqrt.query(idx[v]) << endl; } } // for(int i = 1; i <= n; i++) cout << order[i] << ' '; // cout << endl; // for(int i = 1; i <= n; i++) cout << lb[i] << ' ' << rb[i] << endl; } Edited by author 01.09.2016 20:03 Edited by author 01.09.2016 20:03 |
| poj.org solution app on google play | daydreamer | | 31 Aug 2016 13:57 | 1 |
|
| If your program calculate enough fast for big input and u don't know why you have WA 2, then check it: | IlushaMax | 1086. Cryptography | 31 Aug 2016 02:08 | 2 |
Input can be such as this one: 14000( more than 225) (This problem can be on Pascal where there is byte type) 15000 14999 14888 14777 14666 .... 12313 So you should to change type for variable storing a number of tests) Edited by author 06.04.2016 02:16 Thanks. It seems like test #2 contains 15001 numbers, so you need be careful and create input array of such size. |
| (n ^ 2 + 1)(2 * n * (n + 1) + 1) | murdavron | 1335. White Thesis | 31 Aug 2016 01:58 | 1 |
A = n * n; B = n * n + n + 1; C = n * n + 1; A ^ 2 + B ^ 2 n^4 + (n ^ 2 + n + 1) * (n ^ 2 + n + 1) n^4 + n ^ 4 + 2 * n^3 + 3*n^2 + 2*n + 1 2*n^4 + 2*n^3 + 2*n^2 + 2 * n + n^2 + 1 2 * n*(n ^ 3 + n ^ 2 + n + 1) + n^2 + 1 2 * n ( n(n ^ 2 + 1) + (n ^ 2 + 1)) + n^2 + 1 2 * n((n^2 + 1)(n + 1)) + (n ^ 2 + 1) (n ^ 2 + 1)(2 * n * (n + 1) + 1) |
| 1209. 1, 10, 100, 1000... - WA on #5 | binarysakir | 1209. 1, 10, 100, 1000... | 30 Aug 2016 20:42 | 1 |
If the input is P then the output will be 1 if P can be expressed as 1+(n(n-1)/2) => 1+(n(n-1)/2) = p => 2+n(n-1) = 2p => n(n-1) = 2p-2 To find such n I used floor and ceil of sqrt(2p-2) What's wrong with my logic? #include <bits/stdc++.h> using namespace std; int main(){ double n, k, a, b, root; vector<int> v; cin >> k; while(k--){ cin >> n; root = sqrt((2*n) - 2); a = ceil(root); b = floor(root); if(a == root && b == root){ v.push_back(0); }else{ if(a * b == (2*n) - 2) v.push_back(1); else v.push_back(0); } } for (int i = 0; i < v.size(); ++i){ if(i == v.size() - 1) cout << v[i]; else cout << v[i] << " "; } return 0; } Edited by author 30.08.2016 20:42 |
| Can somebody tell me what's test 15? | mxzf0213 | 2014. Zhenya moves from parents | 30 Aug 2016 18:00 | 2 |
Oh, I know. I should use long long! |
| How to prove? | bsu.mmf.team | 1967. Programmer Casino | 30 Aug 2016 11:24 | 4 |
I've just brute-forced answers for N = 2...500 and found the trick. But how to prove it is always correct or, at least, for the given binary sequences? Yes, there is a proof. Your e-mail, please. Brute force answers for N = 2.. 500 is a vary good hint for this problem ). Thank you. |
| Wa 8 | __Andrewy__ | 2037. Richness of binary words | 29 Aug 2016 17:19 | 3 |
Wa 8 __Andrewy__ 29 Aug 2016 13:40 What is test 8? I tested my program for 9<=n<=200 brute force and my answers is right. For 1<=n<=8 output is: i : NO when i<=n-1 n: aaaaaaaa (n times) This is not true for n = 8. The correct answer is: 1 : NO 2 : NO 3 : NO 4 : NO 5 : NO 6 : NO 7 : aababbaa 8 : aaaaaaaa Thanks! I got AC! My error: I found solution for n<=8 by hand. |
| For those who have WA#4 | Sandu Petrasco | 1654. Cipher Message | 29 Aug 2016 12:07 | 2 |
The test is "abcdeedcbaabcdeedcba"(without quotes). The answer should be ""(empty string). hey mi anwser code is the same, what is the bug |
| wa #4 | Egües | 1654. Cipher Message | 29 Aug 2016 12:00 | 1 |
wa #4 Egües 29 Aug 2016 12:00 hey if one else to know print the anser plese say me..in the test #4 i have a empty string, but the judge say me "wa" in test #4.... why??? help me please. #include <bits/stdc++.h> using namespace std; int main(){ string cad,res; cin>>cad; res = ""; int tam = cad.length(); int i,j; i=0; j=1; int boolean[tam]={0}; while(j<tam){ if(cad[i]==cad[j]){ boolean[i] = 1; boolean[j] = 1; if(i-1>=0){ i-=1; j+=1; }else{ i=j+1; j+=2; } }else{ i=j; j+=1; } } for(int i=0;i<tam;i++){ if(boolean[i]==0) res+=cad[i]; } cout<<res; return 0; } |
| WA27 | reshke | 2065. Different Sums | 28 Aug 2016 22:12 | 4 |
WA27 reshke 25 Aug 2016 20:07 My algo generate array like [1, -1, 2, -2, 3, -3 ...,0], but i got WA27 Any suggetion's? (Bad english) Edited by author 25.08.2016 23:47 Re: WA27 Combatcook [YarSU] 🐸 26 Aug 2016 12:07 You need array like [..., -3, 3, -2, 2, -1, 1, 0], i.e. move all zeros to the beginning of your array, and you'll get AC. Edited by author 26.08.2016 12:12 I don't understand why, but it does not work anyway. Should be output be like 0 1 -1 2 -2 3 -3 4 -4....? Re: WA27 Combatcook [YarSU] 🐸 28 Aug 2016 22:12 My AC program gives answers like (0...0 1 -1 2 -2 3 -3...), but your one - (0 1 -1 2 -2 3 -3 ... n -n ... -n), as I understand. Do you see the difference? |
| Some hints how to solve it | Alexey Dergunov [Samara SAU] | 1106. Two Teams | 28 Aug 2016 01:16 | 5 |
1. Answer always exists. 2. Use DFS for all unmarked vertices and mark them: if current vertex is marked as x, all next must be marked as (x + 1) % 2. (0->1, 1->0) 3. Then just print all vertices marked by 0 (or 1). Edited by author 26.06.2010 04:17 I think, it doesn't need to use DFS. If the edge hasn't incident edges that belong to the first team, we add this edge to the fisrt team. That's all:) If someone has no friends, there is no answer !! I think, it doesn't need to use DFS. If the edge hasn't incident edges that belong to the first team, we add this edge to the fisrt team. That's all:) Thanks, you very helped me) |