Common BoardMY CODE IS: #include<bits/stdc++.h> using namespace std; vector < int > heap; /////MINHEAP void ADD( int m ) { heap.push_back(m); int j = heap.size()-1; while( j != 1 && heap[j] < heap[j/2] ) { //SWAP int carry = heap[j/2]; heap[j/2] = heap[j]; heap[j] = carry; j /= 2; } return; } void REMOVEMIN() { heap[1] = heap[heap.size()-1]; heap.pop_back(); int j = 1; while( ( 2*j < heap.size() && heap[j] > heap[2*j] ) || ( 2*j+1 < heap.size() && heap[j] > heap[2*j+1] ) ) { if( 2*j+1 < heap.size() && heap[2*j] > heap[2*j+1] ) { //SWAP int carry = heap[j]; heap[j] = heap[2*j+1]; heap[2*j+1] = carry; j = 2*j+1; } else { //SWAP int carry = heap[j]; heap[j] = heap[2*j]; heap[2*j] = carry; j = 2*j; } } return; } int GETMIN() { return heap[1]; } int n, a; int main() { ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); heap.push_back(-1); cin >> n; if( n % 2 == 0 ) { int m = n/2 + 1; while(n--) { cin >> a; ADD(a); if( heap.size() - 1 > m ) { REMOVEMIN(); } } int mid1 = GETMIN(); REMOVEMIN(); int mid2 = GETMIN(); bool f = 0; if( mid1 % 2 == 0 && mid2 % 2 == 0 ) cout << mid1/2 + mid2/2; else if( ( mid1 % 2 == 1 && mid2 % 2 == 0 ) || ( mid1 % 2 == 0 && mid2 % 2 == 1 ) ) cout << mid1/2 + mid2/2 << ".5"; else cout << mid1/2 + mid2/2 + 1; } else { int m = n/2 + 1; while(n--) { cin >> a; ADD(a); if( heap.size() - 1 > m ) { REMOVEMIN(); } } cout << GETMIN(); } return 0; } BUT WHY MLE? ?:'( Edited by author 26.10.2019 00:08 Edited by author 26.10.2019 00:09 Edited by author 26.10.2019 00:09 Edited by author 26.10.2019 00:09 I got WA4. Can somebody help? And RE 16... Edited by author 25.10.2019 21:31 Try this tests: 8 AAA BBB CCC DDD WWW XXX YYY ZZZ 11 YYY USES MEDKIT CCC USES MEDKIT YYY USES MEDKIT CCC USES MEDKIT WWW HIT BBB IN BODY WWW HIT YYY IN BODY YYY USES MEDKIT BBB HIT ZZZ IN BODY BBB HIT ZZZ IN BODY BBB HIT ZZZ IN BODY BBB HIT ZZZ IN BODY Answer (it can be another): CORRECT DDD CCC BBB AAA ZZZ YYY XXX WWW 8 AAA BBB CCC DDD WWW XXX YYY ZZZ 8 YYY USES MEDKIT YYY USES MEDKIT YYY USES MEDKIT YYY USES MEDKIT WWW HIT YYY IN BODY WWW HIT YYY IN BODY WWW HIT YYY IN BODY YYY USES MEDKIT Answer: FAKE hello, can u sentme the right code of this programm? thank you very much coloteroritata@gmail.com Do not forget case for "Ask Shiftman for help" ????? Edited by author 19.10.2019 23:42 I use c++,my code is behind. But there is a weird problem . When i define n as int and use cin>>n,the program can't receive the name have more than two word or have symbols like '-'. So i have to define n as a string and transfer the string into a int,why this strange thing happen? #include<iostream> #include<string.h> #include<cstring> using namespace std; int main() { char room[4][1000][210]; memset(room,0,sizeof(room)); int k=0,nth[4]={0}; char n[10]; cin.getline(n,10,'\n'); int len=10; while(n[len]=='\0'){len--;} int temp=1; for(int i=len;i>=0;i--) { k+=(n[i]-48)*temp; temp*=10; } for(int i=0;i<k;i++) { char temp[210],temp1[20]; cin.getline(temp,210,'\n'); cin.getline(temp1,20,'\n'); if(temp1[0]=='S') { strcpy(room[0][nth[0]],temp); nth[0]++; } else if(temp1[0]=='H') { strcpy(room[1][nth[1]],temp); nth[1]++; } else if(temp1[0]=='G') { strcpy(room[2][nth[2]],temp); nth[2]++; } else { strcpy(room[3][nth[3]],temp); nth[3]++; } } /* omit so this is not a correct solution*/ } Hello! Seems there is a duplication in english statement of the problem: >> We know that there are more than P% conductors and less than Q% conductors of all citizens of Ekaterinburg. >>By percentage, we know that there are more than P% conductors and less than Q% conductors of all Russian citizens in this city In the 21st test there are ships with the same azimuth. Edited by author 29.10.2010 23:26 Seems that is still a problem. Test 21 is incorrect. 1104 Task Help me please, I cant understand how can i do my calculations faster? I think that problem with slow input, but how else can i write it? p.s. using stdin, stdout get Time Limit as well maximal = 0 max_digit = -1 arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', \ 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', \ 'U', 'V', 'W', 'X', 'Y', 'Z'] for s in input(): number = arr.index(s) if max_digit < number: max_digit = number maximal += number if max_digit == 0: print(2) else: answer = '' for k in range(max_digit, 37): if not maximal % k: answer = k + 1 break if answer == '': print('No solution.') else: print(answer) Edited by author 14.10.2019 07:30 Edited by author 14.10.2019 07:41 m = [] g = [] d, b = map(int, input().split(' ')) for i in range(1, b+1): n = int(input()) m.append(n) for i in range(1, d+1): g.append(i) for i in range(d): f = 0 for y in range(b): if m[y] == g[i]: f += 1/b*100 f = round(f, 2) a = str(f) if len(a) == 4: print(a+'0%') else: print(a+'%') при 100% проголосовавших выводится 100.0%. Edited by author 30.12.2018 18:16 Попробуй вариант где ответ - 100% I had WA on the 15 test. I saved my answer in a string and i found what i was searching for minimum answer in wrong way, right code for taking minimum from 2 numbers, what are written in strings looks like : if (mn.size() > an.size()) mn = an; if(mn.size()==an.size()) if (mn > an) mn = an; this is a succsesful answer in C, but I want to understand it. Who can help me? #include <stdio.h> #include <stdlib.h> int main() { int n, x=1, FM; int arr[1000]; scanf("%d", &n); if(n<=1000 && n>=3) { for(int i=0; i<n; i++) { scanf("%d", &arr[i]); } FM=arr[0]+arr[1]+arr[2]; for(int i=1; i<n-2; i++) { if(arr[i]+arr[i+1]+arr[i+2]>FM) { FM=arr[i]+arr[i+1]+arr[i+2]; x=i+1; } } } printf("%d %d", FM, x+1); return 0; } Edited by author 10.10.2019 12:53 #include <iostream> using namespace std; int main() { long int n, k; cin >> n >> k; long int a = 1; long int h = 0; if(n == 1){ cout << 0; } else if(n == 2){ cout << 1; } else{ while(n != 0){ if(a > k && a < n){ a = k; n -= a; h++; } else if(a > n){ n = 0; h++; } else{ n -= a; a *= 2; if(a > k){ a = k; } h++; } } cout << h; } } Getting WA#11, give some tests pls Please tell me what could be the problem... WA14, Time limit exceeded, Time work 1.014 Visual C#: if (x!=10.0){ sum=ToInt32((x+0.05)*n); while (sum/n>=x+0.049999999999) sum--; } else { sum=x*n; } while (((ans+sum)/(ans+n))>=y+0.0499999999999 ) ans++; у меня та же ошибка, С# просто медленно работает. Это же решение на ++ заходит using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Globalization; namespace _1484Kino { class Program { static void Main(string[] args) { var userInput = Console.ReadLine().Split(); var x = double.Parse(userInput[0],CultureInfo.InvariantCulture); var y = double.Parse(userInput[1], CultureInfo.InvariantCulture); var n = int.Parse(userInput[2], CultureInfo.InvariantCulture); int count = 0; if (y > 0.9 && x<=10.0) { while (Math.Round(x, 1 )> 1) { x = ((x * n + 1) / (n + 1)); n += 1; count++; } Console.WriteLine(count); } else Console.WriteLine("Impossible"); } } } a=input().split('\n') j=[] for x in a: for xx in x.split(" ") : if(len(xx)>0): j.append( float(xx)**0.5) for i in range(len(j)-1,-1,-1): print(format(j[i],'.4f'))
Time limit test 20 failed on python. Rewrited on C# - everything OK. Edited by author 04.10.2019 02:08 Edited by author 04.10.2019 02:08 I tried to solve this problem in java since we have to accept as many number of lines given in input I wrote a while loop as follows while (in.hasNextLine()) // in is scanner object { // read input and do stuff } but this loop seems to run forever how do I stop the loop from running. |
|