|
|
Общий форумHi, folks! Can anyone give me the source code in C# of this task (mine is already AC) when the timing is less than 0.1 sec? Or can anyone give me the key notes how it can be decreased in almost ten times? Thanks in advance! I presume your sol is O(NM), right? Think a bit. There is O(N+M) solution which definitely has time better than 0.1 sec. 1) Be sure that your algorithm is O(N+M) 2) When calculating percents you should not do: value * 100 / number inside cycle, it is better to calculate "100.0 / number" one time before cycle and then just perfom multiplying. 3) I used float for keeping values, not int. I think it saves time of casting from int to float. When I used 2 and 3 my time for c# decreased from 0.109 to 0.046. #include <iostream> using namespace std; int main() { int cand, ch; cin >> cand >> ch; int* Ch = new int[ch]; double* Cand = new double[cand]; for (int i = 0; i < cand; i++) { Cand[i] = 0; } for (int i = 0; i < ch; i++) cin >> Ch[i]; for (int i = 0; i < ch; i++) { Cand[Ch[i]-1] += 1; } for (int i = 0; i < cand; i++) { printf("%.2f%%\n", (Cand[i]/6.0)*100.0); } } +++++++++++ Why this isn't work? What is the hardcoded value "6" in your code? #include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { int i,j,N,p; std::cin>>N; float cd[N][2],R,dist = 0.0; std::cin>>R;
for(p = 0;p < N;p++) std::cin>>cd[p][0]>>cd[p][1];
i = 0; j = i + 1;
dist = (2 * std::acos(-1.0) * R); while(i < N) { dist += std::sqrt( ( (cd[j][0] - cd[i][0]) * (cd[j][0] - cd[i][0]) ) + ( (cd[j][1] - cd[i][1]) * (cd[j][1] - cd[i][1]) ) ); i++; j = (i + 1) % N; }
std::cout <<std::setprecision(2) << std::fixed <<dist; return 0; } What answer should be for given test? 1 1 1 1 0 Can anyone explain the sample: 3 0 0 0 1 1 0 1 1 0
1 1 3 I dont understand it. The resulting matrix is: 0 1 1 0 1 1 0 0 0 Thanks! I think the correct final matrix must have all 1(s) above or lie on the main diagonal. Any hint to solve this problem ? Edit: nvm, solved it, nice problem with simple algorithm :D Edited by author 12.10.2010 11:07 Edited by author 12.10.2010 11:07 This problem very similar with 1042- central heating Each move (i,j) make switching (and replacing) of some set of pairs of cells. Thus we have linear system over field {0,1) No, the solution is much simplier. You just need to investigate the properties such an operation has. Edited by author 08.12.2016 15:31 Same solution: Visual C++ 2013: Accepted 0.686 8 120 КБ G++ 4.9 C++11: Time limit exceeded 21 1.513 3 924 КБ oh my code.. first use dynamic programming to find the minimum value of distance from 0 and visit 1~m once then to 0, we can get a chain 0--i1-i2--...-im--0 then we consider to cut this chain, use dynameic programming dp[i] to record distance.we cut first i node of the chain.. dp[m] is the result.. I'll try this idea... rt judgement is not stable,sometimes submit AC sometimes submit TLE... 800*800*400 random can AC can someone explain test number 2? please post it (read chunk) here or give some piece of code, many sanx! java AC 0.171 dont use String.toCharArray btw WA7 (add line 2): 1. for (i=p; i<lena; i++) 2. if (a[i]==' ') out2.print(' '); else 3. out2.print('_'); ab ab abcabcabcd | a b bcd | a_ _b _______bcd | so WA 7 controverses with "The words in both utterances are separated with exactly one space; there are no leading or trailing spaces in each line." Edited by author 07.12.2016 06:15 #include <stdio.h> #include <math.h> int main( int argc, char ** argv ) { unsigned long number[256*1024]; int counter = 0; while( scanf("%lu",&number[counter]) != EOF ) { counter++; }
for( counter--; counter >= 0; counter-- ) printf("%.4f\n",sqrt(number[counter])); return 0; } i just found no of storngly connected components and got ac in 0.562 sec after eliminating stack overflow with pragma. how to make it so fast as 0.031 sec and so little memory? You don't have to find strongly connected components. You can just sort vertices topologically and here you will find an answer :) But for topological sorting, graph must be DAG(directed acyclic)? i just keep getting stack overflow,could you please tell me how to eliminate it? Try this test: Input: 5 1 100 0 100 0 100 0 100 0 100 0 2 50 Output: 250 Hello! I have strange WA 22 and really don't understand why. Can anyone help to find the bug in my code. (corrected) Edited by author 04.12.2016 20:25 Your answer to 10000 10000 seems correct, except it misses the very first digit. Thanks! Stupid mistake, as always, just increased size of long number. import java.util.*; import java.io.*; public class MEGA { public static void main(String arg[]) { int k,n,i,sum=0; Scanner scan=new Scanner(System.in); k=scan.nextInt(); n=scan.nextInt(); int[] a=new int[n]; for(i=0;i<n;) { if(scan.hasNextInt()) { a[i]=scan.nextInt(); i++; } } for(i=0;i<n;i++) { sum+=a[i]-k; } if(sum<0) { System.out.println("1"); } else { System.out.println(""+sum); } } } This very simple program is turning out to be a headache. What is Test #3? inside cycle you need to check that (sum + a[i] - k) >=0 Edited by author 04.12.2016 16:18 Edited by author 04.12.2016 16:18 ll n; ll ar[300][300]; int main(){ cin >> n; for(ll i = 1; i <= n; i ++) for(ll j = 1; j <= n; j ++) ar[i][j] = 0; for(ll i = 1; i <= n; i ++){ while(1){ ll x; cin >> x; if(x == -1) break; ar[x][i] = 1; } } for(ll i = 1; i <= n; i ++) ar[i][n+1] = 1; ll col = 1; while(col <= n){ if(ar[col][col] == 1){ for(ll i = 1; i <= n; i ++){ if(i == col) continue; if(ar[i][col] == 1){ //choose ith row for(ll j = 1; j <= n+1; j ++) ar[i][j] = ar[i][j]^ar[col][j]; } } } else{ break; } col ++; } bool f = 1; ll br[300][300]; for(ll i = 1; i <= n; i ++) for(ll j = 1; j <= n; j ++) if(i==j) br[i][j] = 1; for(ll i = 1; i <= n; i ++){ for(ll j = 1; j <= n; j ++) if(ar[i][j]!=br[i][j]) f = 0; } if(!f) cout << "No solution" << endl; else{ for(ll i = 1; i <= n; i ++){ if(ar[i][n+1]==1) cout << i << " "; } } return 0; } I have used basic Gauss algorithm making the augmented matrix equal to an identity matrix. Still getting WA. Please help Thank you :) Edited by author 04.12.2016 10:11 "If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will LOOSE his head." http://grammarist.com/usage/loose-lose/I got AC with a wrong solution during the contest, so I think the test cases might be a bit weak. One example my wrong solution didn't pass is: 7 63713822 It printed 3, while the best answer is 2: 7 -> 8 -> 31856912 -> 31856911 -> 63713822. Can you please add it to the test-set? (Edit: I've fixed my solution now, but others may fail.) Edited by author 03.12.2016 18:42 my code #include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, s = 0, v = 0, maxn = 0; cin >> n; string a, b; for(int i = 1; i <= n; i++){ cin >> a ; for(int i = 0; i <= a.size(); i++){ if(a[0] == 'E' && a[1] == 'm' && a[2] == 'p' && a[3] == 'e' ){ c++; break; } else if( a[0] == 'M' && a[1] == 'a' && a[2] == 'c' && a[3] == 'a'){ s++; break; } else if(a[0] == 'L' && a[1] == 'i ' && a[2] == 't' && a[3] == 't' ){ v++; break; } } cin >> b; } if(c > s && c > v){ cout << "Emperor Penguin"; } else if(s > c && s > v){ cout << "Macaroni Penguin"; } else if(v > c && v > s){ cout << "Little Penguin"; } return 0; } why incorrect WA7 3 000 -> 000000000002 WA10 0 -> 000000000002 |
|
|