|
|
Общий форумvar a,b :integer; begin readln(a,b); if a mod 2 = 0 then writeln('yes') else if b = 0 then writeln('no') else if b div 2 mod 2 = 0 then writeln('yes') else writeln('no'); end. Max bipartite matching algo works fine for O(VE). Please help 1) What does accurate to 8 inch mean.Does it mean accurate upto (8/12) ? 2) Why do we add 2*pi*l to the perimeter of polygon ?Anybody please help. what is the range of "n" ?? I am not the admin, but I will help :) From 1 to 10000. Update: Please ignore - found a small bug in my implementation of heap. ****** My code works fine on 3 4294967295 4294967295 4294967295 and 4 4294967295 4294967295 4294967295 4294967295 what can that be? If I use stl:priority_queue instead of my own heap based pq without making any other changes in the code, I get MLE on #7, i.e. #6 passes. Edited by author 21.09.2015 01:41 Edited by author 21.09.2015 01:41 when i try different inputs my code seems to work fine,but i am stuck at test case #5,can anyone please post it? I used dictionary in python 2.7 to solve this problem, but got MLE on test#21. Can anybody give me some advise or hint about how to deal with this problem? Thanks a lot!!! Here is my code: from sys import stdin num = int(stdin.readline()) notes = {} for i in range(num): key = int(stdin.readline().strip()) if notes.has_key(key): notes[key] += 1 else: notes[key] = 1 max = -1 note = -1 for key, value in notes.items(): if value > max: note = key max = value print note I have MLE too :( def main(): import sys from collections import Counter n = raw_input() lns = sys.stdin.readlines() cnt = Counter(lns) print max(cnt, key=cnt.get)[:-1] main() public class Factorials { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = in.readLine(); StringTokenizer st = new StringTokenizer(str, " ");
int n = Integer.parseInt(st.nextToken()); int k = st.nextToken().length(); if (n >= 1 && n <= 10) { if (k >= 1 && k <= 20) { int limite= n % k, total = n, res= 0, i = 1; do { res= (n - (k * i)); if (res== 0) { System.out.print(total); return; } total *= res; i++; } while (res!= limite); System.out.print(total); } } } } Edited by author 19.09.2015 06:20 could you give test 16 or something like that.. If you are anything like me, go get yourself a cup of coffee and then look for a really stupid bug in your dfs. My program would have failed on the following test: 4 4 0 3 4 0 4 0 0 I use recursion method for solve this problem.But it verdict as TLE. How can i improve my code? Here is my code> #include<iostream> #include<stdio.h> #include<algorithm> using namespace std; int fac(int a,int b) { if(a==1) return 1; else if(a<0 || a==0) return 2; else return a*fac(a-b,b); } int main() { int n,k,a; long long int sum; while(scanf("%d %d",&n,&k)!=EOF) { sum=1; if((n>=1 && n<=10)&& (k>=1 && k<=20)){ sum=sum*fac(n,k); cout<<sum<<endl; } } return 0; }
Remember that X ONLY applies to A and Y ONLY applies to B. For example: 7 5 11 Your answer can be 6 5, but it cant be 5 6. Could anyone helps me with test 7? I wrote simple (dummy) solution - just store all input values in array - then sort it (qsort) - and write array[n/2]. I use free pascal. On my PC program works correct. at least there no any runtime errors. I tested it with input N=1, 2, 3, 5, 1000, 500000. I enabled all checks like I/O, range check, stack check, overflow check, even init variables with garbage... Could s/w get me any clue what can be wrong? my last try - id 6409005 found error in my implementation of quick sort algorithm [code deleted] i, j, x, y: Longword; // <-- change it to LongInt becouse in some cases it can [code deleted] Edited by moderator 24.11.2019 13:28 Edited by author 16.09.2015 13:22 Edited by author 13.09.2015 07:34 3 0 2 3 4 5 6 7 2 0 4 5 6 7 1 3 4 0 6 7 1 2 4 5 6 0 1 2 3 5 6 7 1 0 3 4 6 7 1 2 3 0 5 7 1 2 3 4 5 0 package timus; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Scanner; public class p1933 { public static void main(String[] args) { InputStream is = System.in; Scanner sc = new Scanner(new InputStreamReader(is)); int k = 2 * sc.nextInt() + 1; for (int i = 0; i < k; i++) { int inx = i; for (int j = 0; j < k; j++) { inx++; if (i == j) { System.out.print("0 "); continue; } if (inx > k) inx=1; System.out.print(inx + " "); } System.out.println(); } } } wrong ans #26.Is there any test. 5 1 1 1 2 1 answer is "No" Why? 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 String s = scanner.next(); TreeSet<String> c = new TreeSet<String>(); for (int i=0; i<s.length(); i++) { c.add(s.substring(i)); } int L = c.size() + 1; long total = L - c.first().length(); while(c.size()>1) { String first = c.pollFirst(); String second = c.first(); int lcp = LCP(first, second); total+= L - second.length() - LCP(first, second);; } System.out.println(total); static int LCP(String s1, String s2) { int l = 0; int j = Math.min(s1.length(), s2.length()); for (int i=0; i<j; i++) { if (s1.charAt(i)!=s2.charAt(i)) break; else l++; } return l; } I used Java: The following I did. 1. Declare Stack<Integer>. like this: Stack<Integer> st = new Stack<Integer>(); boolean ok = false; <--// this boolean is tricky.. :)) 2. Then, I iterate from 1 to n init i read X and i checked three given if statements in input. They are: 1.if(x>0){st.push(x);} 2.if(x==-1){pw.println(st.pop());} 3.if(x==0){ int len = st.size(); if(2*len<=n){ st.addAll((Collection) st.clone()); } else{ if(!ok){ // here If you don't use this if statement you will have Memory Limit #42... st.addAll((Collection<? extends Integer>) st.clone()); ok=true; } } } Problem is copying all stack elements... What I am really doing here is using stack clone() method. But When you do so many clones will have MemLimit. That's why I checked that my Stack size and its copies are more than N (2*len>n) then I should copy the whole stack one time not more. And I am thinking that above code worked because <b<stack size wansn't big enough when I cloned last time.... Sorry If I am mistaken and poor english. But this code AC ... Edited by author 13.09.2015 07:35 1 0 1 2 1 0 3 2 3 0 2 0 1 2 3 4 1 0 3 4 5 2 3 0 5 1 3 4 5 0 2 4 5 1 2 0 |
|
|