Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Java solution | Mortrus | 1220. Stacks | 31 Oct 2016 23:22 | 1 | 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 | | test 6: Runtime error (access violation), what can it be? | Abram_TA | 1971. Graphics Settings | 31 Oct 2016 17:27 | 3 | 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 you want to know why when gcd(M, N) = 1 Ans is M + N - 1, come in! | Huang WenHao | 1139. City Blocks | 30 Oct 2016 22:52 | 3 | 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. | | can you tell me how to solve this question | xinxin | 1139. City Blocks | 30 Oct 2016 22:41 | 2 | | | Input not closing | Kevin | 1001. Reverse Root | 30 Oct 2016 22:25 | 2 | 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 | | Hint, very easy | http://www.HelloACM.com | 2005. Taxi for Programmers | 30 Oct 2016 17:49 | 3 | 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); | | how about use recursion | staticor | 1224. Spiral | 30 Oct 2016 17:24 | 2 | 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 | | : please help me why it is wrong | xinxin | 1224. Spiral | 30 Oct 2016 16:22 | 2 | #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. | | Problem 1311 Stable Construction has been changed | Vladimir Yakovlev (USU) | 1311. Stable Construction | 30 Oct 2016 16:01 | 1 | * 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. | | Please help I am getting runtime error in java 1.8 | Kandarp | 1837. Isenbaev's Number | 30 Oct 2016 11:08 | 2 | [code deleted] Edited by moderator 19.11.2019 23:13 check 1 a aa aaa answer a undefined aa undefined aaa undefined | | First number? | monsky | 1003. Parity | 29 Oct 2016 23:46 | 1 | It looks as first input number (sequence length) isn't needed for solution. | | I CAN HELP | Mixael | 1197. Lonesome Knight | 29 Oct 2016 21:27 | 1 | 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!!! :) | | What's wrong my algo? I got WA2, always. | xurshid_n | 2059. Not common palindromes | 28 Oct 2016 04:34 | 1 | Let C = A + '$*&' + B for string C build Palindrom Tree. calculate frequency of each palindrom : f(A,p) calculate frequency of each palindrom : f(B,p) x = count(f(A,p)>f(B,p)) y = count(f(A,p)==f(B,p) && f(A,p)!=0) z = count(f(A,p)<f(B,p)) //little code: freq[i][0] ---> f(A,p); freq[i][1] --> f(B,p). for(int i = 0; i < a.size(); ++i){ add_letter(a[i]); freq[last][0]++;} add_letter('$'); add_letter('*'); add_letter('&'); for(int i = 0; i < b.size(); ++i){ add_letter(b[i]); freq[last][1]++;} for(int z = sz-1; z > 0; z--){ v = link[z]; freq[v][0] += freq[i][0]; freq[v][1] += freq[i][1]; } int x=0,y=0,z=0; for(int i = 2; i< sz; ++i)// skip roots { x += (bool)(freq[i][0] > freq[i][1]); y += (bool)(freq[i][0] == freq[i][1] && freq[i][0] !=0); z += (bool)(freq[i][0] < freq[i][1]); } | | WA test 10 C++ | TIU_Sarexer | 1083. Factorials!!! | 26 Oct 2016 21:47 | 1 | #include <iostream> #include <string> using namespace std; int main() { int num, res; string c, b = "!", a = "!"; cin >> num >> c; res = num; int sign = 0; for (int i = 1; b <= c; i++) { b = b + a; sign = i; } if (num%sign != 0) { for (int i = 1; i*sign < num; i++) { res = res * (num - i*sign); } res = res *(num%sign); } else { for (int i = 1; i*sign < num; i++) { res = res * (num - i*sign); } } cout << res; return 0; } | | Why task score is so different with #1203 Scientific Conference? | ToadMonster | 1112. Cover | 26 Oct 2016 20:59 | 1 | Solved both tasks with the same algorithm. Think this task is over-valued. Edited by author 26.10.2016 20:59 | | TLE | beka | 1846. GCD 2010 | 26 Oct 2016 16:28 | 1 | TLE beka 26 Oct 2016 16:28 just submitted code and got TLE on 15test, submitted same code after few minutes and got accepted. submitted again and got TLE on 24test for same code. | | Time Limited | Shohruh_1999 | 1209. 1, 10, 100, 1000... | 26 Oct 2016 14:33 | 1 | | | Problem 1992 CVS has been rejudged | Vladimir Yakovlev (USU) | 1992. CVS | 25 Oct 2016 17:41 | 3 | All solutions have been rejudged with the current time limit. Also, few more tests have been added. 10 authors have got AC while 23 other have lost. I have replaced standart C# input functions with my low level parse method and got Accepted. Is this the goal of that rejudgement? Well, I just resubmitted the previous solution with visual c++. I do every query O(1) operations and use scanf and printf. I think the version of your g++ compiler is not that good. There were some troubles with scanf and printf at some new versions of g++ compiler. | | why i always wa in test #11. | cse_acm_jsh | 1937. Davy Jones’s Organ | 25 Oct 2016 16:16 | 2 | | | If you get WA11!!! | xurshid_n | 1937. Davy Jones’s Organ | 25 Oct 2016 16:15 | 1 | source code of algorithm Manaker (find all palindroms in O(n)), where explained in e-maxx.ru is incorrect :), see comments to below of that page. Edited by author 25.10.2016 16:17 |
|
|