Common Boardi see N%3 solution everywhere but does anyone have any explanation as to why the guy who has mod-3 no of stones should lose. Some logical or mathematical reason would be much appreciated. Let's see that for every number k which is an integer power of 2, k mod 3 = 1, or 2. (To be exact - table of (k mod 3) for {1,2,4,8,16,32,64... is: {1,2,1,2,1,2,1,2,1,2,... So, you can see that it is impossible to get from (mod 3 = 0) position to another (mod 3 = 0) position in one move. Let n (number of remaining stones) = 3. The first player can make x=1 or x=2 move, but now the second player can counter by making 3-x move and win. So n=3 is a losing position. We have proven that it is impossible to get from one number of stones divisible by 3 to another number of stones divisible by 3 in one move. We can now prove, by the rule of mathematical induction, that every position with n divisible by 3 is a losing position. Let's look - if the first player begins from position with 3*x stones, after any move the opponent can counter by '1' or '2' move and create another position with lesser number of stones, also divisible by 3. In the second case, when first player begins from position with number of stones not divisible by 3 (so n%3=1 or n%3=2), _he_ can now make a '1' or '2' move which will create a (mod 3 = 0) position (which was proven to be losing) for his opponent. Thus, due to arbitrarity of n, any (n mod 3 != 0) position can create a losing position for the second player in one move, so it is a winning position for the first player. Consider these. number of leave stones 1 win 2 win ---- because we can choose 1 or 2 3 lose sure ---- because if you choose 1 number of leave stones == 2 or if you choose 2 number of leave stones == 1 each player will be the winner. 4, 5 win, choose 1, 2 sure each player will be take 1 or 2 sure you will be the winner. 6 lose 7, 8 win .... we can assume if N mod 3 == 0 sure that person will be lose, otherwise we can choose the minimum of first number of stones = N mod 3 so each player will be the loser.
Also we can consider a Grandy function for n from 1 to .... g[0] = 0 g[1] = 1 g[2] = mex{0, g[1]} = 2 g[3] = mex{g[1], g[2]} = 0 g[4] = mex{0, g[2], g[3]} = 1 g[5] = mex{g[4], g[3], g[1]} = 2 ...... g[n] = n%3 More strictly can be proved using mathematical induction why should i declare 128*1024 size of memory for 256KB described in the problem? my code goes here: #include<iostream> #include <cstdio> #include <cmath> double buf[128 * 1024]; int main() { int i = 0; unsigned long long n; while (scanf("%llu", &n) != EOF) { buf[i ++] = (double)sqrt(n * 1.0); } for (; --i >= 0; ) { printf("%.4lf\n", buf[i]); } return 0; } // why 128*1024 ? Because 256kb means there's at most 128kb of digits and 128kb of spaces? Here the array size is 128*1024 and it is double. So doesn't the array hold 128*1024*8 KB of memory(8 bytes for each element) ? Well you don't necessarily need double, you may use long long int for keeping numbers. Of course, it's 8 bytes either way, but you just don't know whether your numbers are going to be a few huge ones, or a ton of 1-digit ones, so you just have to be on a safe side. Hello, I've not found a topic about this test. Does anyone know what is it? I'm just searching from the half of the string to find where can be the center of a palindom. Thank you The follwing is my pgm. Could some give a test case not satisfied here? var s1,i:integer; f:boolean; a2,b2,a1,b1,a,b:real; begin f:=false; read(a); read(b); a1:=a/100; b1:=b/100; if b<>0 then i:=trunc(1/b1); a2:=a1*(i); b2:=b1*(i); while not f do begin if (((trunc(b2)<>trunc(a2)))and (frac(b2)<>0) then f:=true; a2:=a2+a1; b2:=b2+b1; i:=i+1; end; i:=i-1; writeln(i);
end. Got ac by using double not float by accepting the input, so wired. #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> const long long mod=1000000007; const int nmax=200; int n,m,t,p; long long v[nmax],fact[nmax],step[nmax]; bool used[nmax]; bool a[nmax][nmax]; long long ans; void DFS(int v) { for(int j=1;j<=n;j++) { if(a[v][j] && !used[j]) { t++; used[j]=true; DFS(j); } } } bool FindCycle(int v,int pr) { bool f=false; for(int j=1;j<=n;j++) { if(a[v][j] && j!=pr) { if(used[j]) return true; else { used[j]=true; t++; f=f | FindCycle(j,v); } } } return f; } void main() { scanf("%d%d\n",&n,&m);
if(n<=2) { printf("1"); return; }
fact[0]=1; for(int i=1;i<=n;i++) fact[i]=fact[i-1]*((long long)i) % mod;
for(int i=1;i<=n;i++) step[i]=0;
for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) a[i][j]=false; }
for(int i=1;i<=m;i++) { scanf("%d\n",&t); if(!a[i][t]) { a[i][t]=a[t][i]=true; step[i]++; step[t]++;
} }
p=1; while(p<=n && step[p]<=2) p++; if(p<=n) { printf("0"); return; }
for(int i=1;i<=n;i++) used[i]=false;
for(int i=1;i<=n;i++) { if(!used[i]) { used[i]=true; t=1; if(FindCycle(i,-1)) { if(t<n) { printf("0"); return; } if(t==n) { printf("2"); return; } }
} }
for(int i=1;i<=n;i++) used[i]=false; p=0; ans=1; for(int i=1;i<=n;i++) { if(!used[i]) { p++; t=1; used[i]=true; DFS(i); if(t>1) t=2; ans*=((long long)t) % mod; } } ans=ans*fact[p-1] % mod; while(ans<0) ans+=mod; printf("%lld",ans); } Test #9 is the first test with N = 100, and it's also the first with M = 100. I've generated 2k+ random tests with those parameters but got no difference between programs, so i guess it should be a quite specific test. Anyways, the right answer to that one is 950M ± 10M, and yours is 580M ± 10M. В-общем,я в своём репертуаре. ТОТ ЖЕ ГОВНОКОД, но на ПАСКАЛЕ, дал АС! P.S. Glad to see you, Jane Soboleva!!! Oh, i guess it was something syntax-specific then, like in a certain place there goes a wrong order of operations or something like that... P.S. Glad to see you, Jane Soboleva!!! <3 a a b a a answer: 1 Input doesn't contain two equal words Sorry... It test is incorrect. If you have WA4 java. Put 10^7 instead of 10^6 Edited by author 30.09.2013 09:17 Edited by author 30.09.2013 09:17 ___Test 13 Fominykh Isenbaev BBB BBB CCC AAA Ayzenshteyn Oparin Samsonov Ayzenshteyn Chevdar Samsonov Dublennykh Fominykh Ivankov Burmistrov Dublennykh Kurpilyanskiy Cormen Leiserson Rivest Oparin AA AAA Isenbaev Oparin Toropov AA DD PP PP QQ RR RR SS TT TT Toropov Oparin ____correct answer: AA 2 AAA 2 Ayzenshteyn 2 BBB 1 Burmistrov 3 CCC 2 Chevdar 3 Cormen undefined DD 3 Dublennykh 2 Fominykh 1 Isenbaev 0 Ivankov 2 Kurpilyanskiy 3 Leiserson undefined Oparin 1 PP 3 QQ 4 RR 3 Rivest undefined SS 3 Samsonov 2 TT 2 Toropov 1 Other lexicographical order is correct also: AA 2 AAA 2 Ayzenshteyn 2 BBB 1 Burmistrov 3 CCC 2 Chevdar 3 Cormen undefined DD 3 Dublennykh 2 Fominykh 1 Isenbaev 0 Ivankov 2 Kurpilyanskiy 3 Leiserson undefined Oparin 1 PP 3 QQ 4 Rivest undefined RR 3 Samsonov 2 SS 3 Toropov 1 TT 2 You can see that Rivest undefined RR 3 Samsonov 2 SS 3 Toropov 1 TT 2 are ordered in other lexicographical order. You're wrong. Problem says: "The first letter of a name is capital and the other letters are lowercase", so tests can't contain names like these "RR, TT, AAA, etc.". 7 7 Isesnbaev Oparin Toropov Ayzenshteyn Oparin Samsonov Ayzenshteyn Chevdar Samsonov Fominykh Isesnbaev Oparin Dublennykh Fominykh Ivankov Burmistrov Dublennykh Kurpilyanskiy Cormen Leiserson Isenbaev test this case Didn't notice that problem is not for Java, so I solved it. Maybe someone will need the solution. Solution without checking of stacks for emptiness. import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; import java.util.StringTokenizer; public class HelloWorld { public static void main (String[] args) { HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>(); Scanner reader = new Scanner(System.in); int n = reader.nextInt(); reader.nextLine(); for (int i = 0; i < n; i++) { String command = reader.nextLine(); StringTokenizer tokenizer = new StringTokenizer(command); command = tokenizer.nextToken(); if ("PUSH".equals(command)) { int key = Integer.parseInt(tokenizer.nextToken()); int value = Integer.parseInt(tokenizer.nextToken()); if (map.containsKey(key)) { map.get(key).add(0, value); } else { map.put(key, new ArrayList<Integer>()); map.get(key).add(0, value); } } else if ("POP".equals(command)) { int key = Integer.parseInt(tokenizer.nextToken()); if (map.containsKey(key)) { System.out.println(map.get(key).get(0)); map.get(key).remove(0); } } } } } Edited by author 31.10.2016 23:24 Edited by author 31.10.2016 23:26 Here is my not accepted solution: #include<iostream> #include<string> using namespace std; double P(int power[],string names[],int a,int n,int video_power,int on_or_off[],int w,int h){ a=video_power; for(int i=0;i<n;i++){if(on_or_off[i]==1){a/=power[i];}} double res=a/(w*h); return res; }
int main() { int n; cin>>n; string * names = new string[n]; int * power = new int[n]; for (int i=0;i<n;i++){ cin>>names[i]; cin>>power[i]; } int w,h,video_power; cin>>w>>h>>video_power; double results[100]; int on_or_off[100]; for(int i=0;i<n;i++){on_or_off[i]=1;} int e=0; int a=video_power; for (int i=0; i<n;i++){ a/=power[i]; } double prodyctivity=a/(w*h); results[e]=prodyctivity;e++; int m; cin>>m; for(int i=0; i<m; i++){ string change,change_name; cin>>change; if(change[0]!='R'){ cin>>change_name; for(int y=0;y<n;y++){ if(change=="On" && change_name==names[y]){ on_or_off[y]=1; prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h); results[e]=prodyctivity;e++; } else if(change=="Off" && change_name==names[y]){ on_or_off[y]=0; prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h); results[e]=prodyctivity;e++; } } } else{ int a1,a2; cin>>a1>>a2; w=a1;h=a2; prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h); results[e]=prodyctivity;e++; } } for(int i=0;i<m+1;i++){ if(results[i]<10){cout<<"Slideshow"<<endl;} else if(results[i]>=60){cout<<"Perfect"<<endl;} else{cout<<"So-so"<<endl;} } } Please! I dont know where your mistake is, but anyway this solution is wrong. Check the max test case: n = 99999 and each option is 100 (100^99999). Your double precision not enough for AC. It's 100000 results, not 100 results, hence the access violation on your tiny array If the plane fly across a edge and it will produce a point then produce a new block so the answer add one. If gcd(M, N) = 1, it means there is no situation that the plane fly across the crossroads. See from left to right it produce M point and see from north to south it produce N point, but one is calculate twice, so there are M + N - 1 points and Ans is M + N - 1. and what if gcd(m,n)!= 1 ?? Sorry, can't get you and what if gcd(m,n)!= 1 ?? Sorry, can't get you Reduce to smaller problem (m / gcd(m,n), n / gcd(m,n)) and then use it to solve the original problem. I've perused over some of the other solutions here, tried to come up with something original, but I'm having a difficult time understanding why it won't stop letting me input in Eclipse, and how to deal with that...Here's my code: import java.util.*; public class ReverseRoot {//start class public static void main(String[] args) {//start main Scanner in = new Scanner(System.in); ArrayList<Long> array = new ArrayList<Long>(); array.add(in.nextLong());
while(in.hasNextLong()) { array.add(in.nextLong()); } in.close();
for (int i = array.size(); i > 0; i--) System.out.printf("%.4f%n", Math.sqrt((double)array.get(i))); }//end main }//end class Try to run program from command line: java Solution < 1.txt And 1.txt contains list of numbers, like below: 1 2 3 Edited by author 30.10.2016 22:25 s1 = ['1 2 3 4 5', '1 4 3 2 5', '1 3 2 4 5', '1 3 4 2 5'] [deleted] Edited by author 24.06.2014 02:43 int order[3] = {2, 3, 4}; do { if (order[2] == 3) continue; calculate_distance(); } while (next_permutation(order, order + 3); think about : F(N,M) = F(N-? , M- ? ) and give the initial values. The number of steps is too big. By doing a single recursive step you reduce the size of the original problem to (N - 2, M - 2). If we were to reduce the size to (N / 2, M / 2) (notice that we changed minus sign to division), then we could solve it recursively. Instead you should think of this problem as a whole. There are N rows and M columns. So some part of the robots path is by row and some part is by column: path = row|column|row|column|row|column... And we are counting the number of signs | in the path. As we see, each column is surrounded by sign | from both of its sides: "|column|". The first rough estimate that comes to mind after this observation is that probably the robot does 2 * (number of columns) turns. And by thinking of different specific cases of (N, M) we can turn this estimate into a true measure of the number of turns of the robot in the general case. Edited by author 30.10.2016 17:25 #include<stdio.h> #include<string.h> int f(int n,int m) { if(n==1||m==1) return 0; if(n==2&&m>1) return 2; if(n==3&&m==2) return 3; if(m>2&&n>2) return f(n-2,m-2)+4; } int main() { int n,m; scanf("%d %d",&n,&m); printf("%d",f(n,m)); fflush(stdin); getchar(); return 0; } Input "N=1 M=1" doesn't give you zero. * The minimal height of the wall is set to 1 (previously 0). * The total number of bricks is set to be between 1 and 100 000 (previously, not more than 1 000 000, but there were no such tests). * New tests have been added. * All accepted solution have been rejudged, 98 authors have lost their AC. [code deleted] Edited by moderator 19.11.2019 23:13 check 1 a aa aaa answer a undefined aa undefined aaa undefined It looks as first input number (sequence length) isn't needed for solution. int a[10]={-1,1,2,2,1,-1,-2,-2,-1,1}; ... for(i=1;i<=8;i++) if(x+a[i-1]>0 && x+a[i-1]<9 && y+a[i+1]>0 && y+a[i+1]<9) h++; DO IT!!! :) |
|