Common BoardWith 1 Mb memory limit? :-) AC now:) Edited by author 11.02.2007 15:03 You should store in queue n/2 +1 numbers I can't understand you... How I can do it? At first push n/2+1 numbers then do this 1 read next number 2 push it to queue 3 pop biggest element 4 goto 1 At the end use 2 or 1 top elements for answer Thank you very much!!! I got AC! I use priority queue as you said,but still MLE#7.Maybe I'm wrong,here is my code: #include<iostream> using namespace std; #include<queue> int main() {std::priority_queue<int>pr; int n,i,a; cin>>n; for(i=1;i<=n/2+1;i++) {cin>>a; pr.push(a); } i=n/2+2; while(i<=n){ cin>>a; pr.push(a);i++; pr.pop(); } if(n%2!=0) cout<<pr.top()<<".0"<<endl; else {a=pr.top(); pr.pop(); if(a%2+pr.top()%2==2) cout<<a/2+pr.top()/2+1<<".0"<<endl; else if(a%2+pr.top()%2==0) cout<<a/2+pr.top()/2<<".0"<<endl; else if(a%2+pr.top()%2==1) cout<<(a/2+pr.top()/2)<<".5"<<endl; } return 0; } Thank!!! Edited by author 18.09.2007 19:59 int v[250000/2+3]; for(; i < n/2+1; ++i) cin >> v[i]; make_heap(v,v+n/2+1); for(; i < n; ++i){ cin >> v[n/2+1]; push_heap(v,v+n/2+2); pop_heap(v,v+n/2+2); } BTW(1), there is no need for "unsigned" since input is less than 2^31-1 BTW(2), there is no need to avoid "double a" in calculation and output of the the final answer: cout << setprecision(1) << fixed << a << endl; BTW(1), there is no need for "unsigned" since input is less than 2^31-1 There was an example of possible input in early posts on the forum: [(2^31 - 1) + (2^31 - 1)] / 2 = 2^31 - 1 but ((2^31) - 1) + ((2^31) - 1) = 4 294 967 294 so if you don't know how to manage such a thing you should use unsigned int. BTW there is no differences in allocated memory between "unsigned" and "signed int" but "unsigned" work faster. one way to avoid overflow of calculating ((2^31) - 1) + ((2^31) - 1) is to compute ((2^31-1) * 0.5) + ((2^31-1) * 0.5) instead of ( ((2^31) - 1) + ((2^31) - 1) ) * 0.5 I have learnt a lot ,thanks. I use G++ 4.9 and get MLE. Then I try G++ 4.9 C++ 11 and AC. Why? :( All ok!) Edited by author 03.10.2015 14:49 Edited by author 03.10.2015 14:49 Edited by author 05.10.2015 18:55 Could someone write input data for test 5? My program works properly for the input below: 6 1 4 5 6 7 9 Edited by author 08.04.2013 17:51 I've already found bug in my alghoritm. It gets wrong answer on the following input: 5 11 10 8 7 6 May be this test helps someone. Thanks for the information! Hi Can anybody help me to convert my recursive solution to iterative. Can i Post code here? If your solutions are in MAX_SUMxMAX_DIGITS matrix, then just fill the solutions row-by-row. This way it is guaranteed that at each step you have all solutions you have to sum up already computed. The statement is poor. It says M*N, which is usually considered as M in x-axis and N in y-axis. But actually, for M=2,N=3 they mean xxx xxx (That can be infered from "The next M lines contain a matrix with nonnegative integer elements") And we can't understand that from Sample because it's a square! *** So,if you always get WA2,try to swap m,n. *** I changed scanf("%d %d",&m,&n) to scanf("%d %d",&n,&m) and got AC. Sorry for my poor English. Edited by author 15.08.2009 11:30 Edited by author 15.08.2009 11:31 Nevermind, i'm stupid... another hint for WA #2: when generate your numbers a^2+b^2=c^2, and then you invert things like (+3X, +4X) for X=1...while coordinates are valid, and then later you want to invert (+6X, +8X) — don't! Because you invert the same place once more. Edited by author 02.10.2015 16:50 What is test case 8? I met the same problem.Have you solved?? Anyone have idea what could be the problem ?? Any test case you would suggest ? Thanks Try 1 4 Answer 1 4 Yes When i run it on my machine the answer for 1 4 is 1 4 I am using byte array, should i use int array instead.. ?? Idk how but it worked for an earlier problem I changed the byte array to short Now I get the above test case wrong.. Why so ???!!! Please somebody give test 36 || some hint to pass this test! Thank you very much! Edited by author 02.01.2011 17:54 Please help me! WA #36 is a result of something like 11 + 12 --> 23 0/1 I threw away the 0/1 part for such cases and got AC. #include <iostream> #include <math.h> #include <string.h> using namespace std; const int ArrSize = 100; struct Number { int Num; char Get[3]; }; const Number tel[10] = { { 0, 'o', 'q', 'z' }, { 1, 'i', 'j' }, { 2, 'a', 'b', 'c' }, { 3, 'd', 'e', 'f' }, { 4, 'g', 'h' }, { 5, 'k', 'l' }, { 6, 'm', 'n' }, { 7, 'p', 'r', 's' }, { 8, 't', 'u', 'v' }, { 9, 'w', 'x', 'y' } }; void Func(int num[], int, char t[][51]); char f1[ArrSize], f2[ArrSize], temp[ArrSize + 2], temp2[50000][51]; unsigned int counter1 = 0, counter2 = 0, k = 0, size = 0; void main() { int number[ArrSize], voc; for (;;) { cin.getline(temp, ArrSize + 1); if (temp[0] == '-' && temp[1] == '1') break; while (size<strlen(temp)) { number[size] = temp[size] - '0'; size++; } cin.clear(); cin >> voc; cin.get(); for (int j = 0; j < voc; j++) { cin.getline(temp2[j], 50); } Func(number, voc, temp2); if (strlen(f2) != 0) { int temporary = 0; while ((strlen(f2) - temporary) != 0) { if (temporary != 0) cout << ' '; cout << temp2[(f2[temporary] - '0')]; temporary++; } cout << endl; } else cout << "No solution." << endl; k = size = counter1 = voc = 0; memset(f1, NULL, ArrSize); memset(f2, NULL, ArrSize); memset(temp, NULL, ArrSize + 1); for (int z = 0; z < 51; z++) memset(temp2[z], NULL, 51); memset(number, 0, ArrSize); } } void Func(int number[], int voc, char temp2[][51]) { unsigned int j = 0; for (int i = 0; i < voc; i++) { if (strlen(temp2[i])<=(size - k)) for (j = 0; j < strlen(temp2[i]); j++) { if ((tel[number[j + k]].Get[0] != temp2[i][j]) && (tel[number[j + k]].Get[1] != temp2[i][j]) && (tel[number[j + k]].Get[2] != temp2[i][j])) break; } if (j == strlen(temp2[i])) { k += j; f1[counter1] = i + '0'; if (size > k) { counter1++; Func(number, voc, temp2); counter1--; } if ((counter2 > counter1 || strlen(f2) == 0) && k == size) { strcpy_s(f2,f1); counter2 = counter1; } k -= j; f1[counter1] = NULL; } } } Is something wrong with the input file format, is not as in the specification ( i lost 4 hours because of this ). To be sure read it with Scanner ( if you use java ). Edited by author 22.05.2012 02:47 Edited by author 22.05.2012 02:47 I have the same problem. In what direction i must dig? (C# is my language) OK, I did it. You need to read input until end (C++ style!). In C# you can use structure like that: while(Console.In.Peek() != -1) { //read input } Good luck :) I have the same problem, I am a python programer here is my code: import sys sys.setrecursionlimit(10**5) def find_tour(G): """ Where G is an undirected graph """ tour=[] visited_edges=set() def recurse(u): for v in G[u]: if (u,v) in visited_edges:continue visited_edges.add((u,v)) recurse(v) tour.append(u) recurse(G.keys()[0]) tour.reverse() return tour from collections import defaultdict def main(): G=defaultdict(list) n=input() for t in range(n): l=map(int,raw_input().strip().split()) for i in range(1,l[0]+1): G[l[i]].append(l[i+1]) r=find_tour(G) if len(r) and r[0]==r[-1]: s=" ".join(map(str,r)) s=str(len(r)-1)+" "+s print s else:print 0 main() The error is in the reading phase, but when I change the read part to: try: tokenizer=chain.from_iterable(line.strip().split() for line in stdinf) n=int(tokenizer.next()) for i in range(n): m=int(tokenizer.next()) u,v=-1,int(tokenizer.next()) for j in range(m): u=v v=int(tokenizer.next()) G[u].append(v) # print G except: pass I got an error in the 1st test case even when I dont have the same problem in my laptop. Thanks for any help that you can give me. OK, I did it. You need to read input until end (C++ style!). In C# you can use structure like that: while(Console.In.Peek() != -1) { //read input } Good luck :) Yes, got problem with test #5 input. Got AC after reading it the following way (python 2.7): all_input = iter(sys.stdin.read().strip().replace('\n', ' ').split(' ')) n = int(all_input.next()) for _ in xrange(n): m = int(all_input.next()) u = all_input.next() for i in xrange(m): v = all_input.next() ... u = v Edited by author 29.09.2015 06:14 Edited by author 29.09.2015 06:14 Thanks to Alexander Kulkov for preparing! Спасибо за задачу!!! Очень интересная и полезная!!! А ещё такой вопрос, Вы можете сказать, сколько (в сек.) работает решение жюри? Привет. Напиши мне в ЛС на codeforces или на e-mail. Обсудим :) Edited by author 10.05.2016 22:50 min = leaves + disconnectedCycles max = acyclicNodes + disconnectedCycles + connectedCycles /******************************* In The Name Of God ******************************** Problem ID: 1086 - Cryptography ( http://acm.timus.ru/problem.aspx?space=1&num=1086)Time Limit: 2.0 sec Memory Limit: 16 MB Author: Hamidreza Hosseinkhani (hosseinkhani@live.com) ***********************************************************************************/ #include <iostream> using namespace std; #include <cmath> bool prime( float num ) { for ( int i = 2 ; i <= sqrt( num ) ; i++ ) if ( !( (int) num % i ) ) return false; return true; } int main() { //ifstream cin( "in.txt" ); //ofstream cout( "out.txt" ); int k, n, *list, max = 0; cin >> k; list = new int [k]; for ( int i = 0 ; i < k ; i++ ) { cin >> list[i]; if ( list[i] > max ) max = list[i]; } int *primes = new int [max]; for ( int i = 2, c = 0 ; c < max ; i++ ) if ( prime( i ) ) { primes[c] = i; c++; } for ( int i = 0 ; i < k ; i++ ) cout << primes[list[i] - 1] << endl; return EXIT_SUCCESS; } 1) Your solution takes too long time to precalculations. Try do it faster ;) 2) do not public your AC solutions - show respect to authors who have not solved it yet Edited by author 30.05.2011 14:05 lol why would you use live.com? :D Totally a show off. Edited by author 26.09.2015 13:34 Edited by author 26.09.2015 13:34 Задача не принималась с ошибкой java:1: error: class, interface, or enum expected при прикреплении файла. Когда отправил то же самое в виде текста - все принялось. С чем это может быть связано? Текст задачи следующий: import java.io.*; import java.util.*; public class SQ2 {
public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); double[] al = new double[131072]; int i = 0; while(in.hasNextDouble()){ al[i++] = in.nextDouble(); }
for(;i>0;i--){ long i1 = (long)Math.round(Math.sqrt(al[i-1])*10000); out.format("%.4f%n",(double)i1/10000); } out.flush(); in.close(); } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; //URAL STEAKS public class P { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); String line; int ans; line = br.readLine().trim(); String str[]; str = line.split(" "); int N = Integer.parseInt(str[0]); int K = Integer.parseInt(str[1]); if(2*N%K>1){ ans = (2*N/K)+1; }else{ ans = (2*N/K); } out.print(ans); out.flush(); } } При N = 1, K = 2 программа выдаёт 1, а должна 2 по условию задачи. Please give answer in English... if (n<=k) the answer is 2 I passed 5 test, when change method is_inside: from return (0<=i&&i<=n&&0<=j&&j<=m) to return (0<=i&&i<n&&0<=j&&j<m) what test failed me? How to solve this problem ? Flow seems not enough because of the vertexes of "anything" type. Flow can solve it but there's a better way in fact. Edited by author 11.10.2009 21:40 Could you tell me, please, how to construct the graph for a flow ? you should construct bipartite graph. for example , you have people with ranks: 2 4 6 8 10 2 , 6 , 10 - to the left side 4 , 8 - to the right side I tried to use Kuhn (max pair-combination), but get WA#11. And don't know, what to do next... You always can put all the people with skill < 2 (modulo 4) to the left part and all the people with skill >= 2 (modulo 4) to the right. Definitely, all the edges will connect vertices from different parts, so this graph will be bipartite. My algo is O(n^3),but it got TLE 11! What is right algo here? My algo is O(n^2*m) and AC in 0.093 It is standart bipartite matching algo My algo is O(n^2*m) and AC in 0.093 It is standart bipartite matching algo I was use Hopcroft_Karp algo (from wiki) and AC. 0.031 s. You always can put all the people with skill < 2 (modulo 4) to the left part and all the people with skill >= 2 (modulo 4) to the right. Definitely, all the edges will connect vertices from different parts, so this graph will be bipartite. But why will the maximum match in this graph will be answer to the problem? I used a Hopcroft-Karp algorithm to solve this problem and got AC in 31 ms. So, not bad :) |
|