Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
WA What's wrong with my code? | P0Vlin | 1025. Демократия в опасности | 29 ноя 2022 20:09 | 1 |
#include <iostream> #include <algorithm> using namespace std; int main(){ int n, half, votes, q[101]; cin >> n; half = (n/2) + 1; for (int i=0; i < n;i++) cin >> q[i]; sort(q,q+n); for (int i =0;i<half;i++) votes += (q[i]/2) + 1; cout << votes; return 0; } |
what wanted in this problem? | ruhulkuddus.cse@gmail.com | 1025. Демократия в опасности | 24 янв 2022 19:11 | 1 |
I do here according to the test case description. But I need some hint what actually wanted in this problem. |
Accepted C# | Адель | 1025. Демократия в опасности | 28 авг 2021 19:18 | 2 |
using System; using System.Linq; namespace e3 { class Program { public static void Main(string[] args) { int k=int.Parse(Console.ReadLine()); int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray(); int temp; for (int i = 0; i < k - 1; i++) { for (int j = 0; j < k - i - 1; j++) { if (arr[j] > arr[j + 1]) { // меняем элементы местами temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } }
int s=0; for (int i = 0; i < k/2+1; i++) { s=s+(arr[i]/2+1); } Console.WriteLine(s);
} } } Edited by author 28.08.2021 19:25 |
Runtime error java | Schwarz | 1025. Демократия в опасности | 21 май 2020 02:02 | 2 |
Прекрасно работает в IDE, а на сервере ошибка. Объясните в чем дело import java.util.LinkedList; import java.util.Scanner; import static java.util.Collections.sort; public class Bird { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i = sc.nextInt(); sumGol(minKol(i), toConteiner(i)); } public static LinkedList<Integer> toConteiner(int i) { Scanner sc = new Scanner(System.in); String[] str = sc.nextLine().split(" "); LinkedList<Integer> in = new LinkedList<>(); for (int j = 0; j < str.length; j++) in.add(Integer.parseInt(str[j])); return in; } public static int minKol(int i) { if (i % 2 != 0) i = i / 2 + 1; else i = i / 2; return i; } public static void sumGol(int i, LinkedList<Integer> l) { sort(l); int sum = 0; for (int j = 0; j < i; j++) { sum = sum + minKol(l.get(j)); } System.out.print(sum); } } На этот вопрос есть где-нибудь ответ? У меня другой код, та же ошибка. ( |
Why wrong answer? | Alexander | 1025. Демократия в опасности | 21 фев 2020 01:55 | 2 |
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a; int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { cin >> a; v.push_back(a); } n = 0; sort(v.rbegin(), v.rend()); for (int i = v.size()-1; i > (v.size()-2) / 2; i--) n += (v[i]+1)/2; cout << n << endl; } You should iterate from v.begin to v.end. No the reverse way. |
Proper hints for all the test cases out there | samio | 1025. Демократия в опасности | 21 фев 2020 01:53 | 1 |
Sort the n teams and take the first (n/2 + 1) team's people (by people i mean, array[i]/2 + 1). If you have problem understanding what i have just written or for better understanding, give this a go : https://ideone.com/vD6SAm |
Doubt regarding solution | ashwin | 1025. Демократия в опасности | 25 апр 2019 02:14 | 3 |
hello all, I am new to programming problems.. I have a doubt regarding the solution.. I got the answer accepted but i want to know how did this problem come under the category of sorting?? I tried thinking a lot but i could never even guess that we have to use sorting.. I only came to know after i saw the hints in this forum. SO please can anyone explain how did this problem come under sorting?? one way to solve this program is : you should sort the array in witch is written quantity of members in each group . Then you should run this array from the first to k div 2 and remember sum of ((each element div 2) +1) this will be minimal quantity of supporters of the party, that can put into effect any decision. Sorry for bed English if you couldn't understand write me and i'll try to explain ... Still i can't understand the problem. Can you explain again pls. |
If you have WA #5 | german_goncharov | 1025. Демократия в опасности | 10 апр 2019 20:36 | 1 |
You can use for test this numbers: 9 3 11 7 9 13 25 7 11 5 The answer is 18. --- Hint: Use sort? Try to think about what you sort |
Accepted !!! =) | Jairls18 | 1025. Демократия в опасности | 7 апр 2019 15:05 | 5 |
[code deleted] Edited by moderator 20.11.2019 00:02 I understood the solution. But I didn't understand the logic, why 1 is added before dividing the number? Thank you. Because to get vote from i group you need to have more than a half votes. For example, If 7 you have 7 guys in a group, you need to have 4 votes. 7/2 = 3 3+1 = 4 Why you sorted the array?. Is there any need of it?. |
why wrong answer # test case 5 | Anupam Patel | 1025. Демократия в опасности | 7 окт 2018 18:28 | 1 |
Hello , Can someone please tell me why I am getting wrong answer for test case 5? I have used straight forward approach. ``` #include <stdio.h> 2 3 int group_distribution[10001]; 4 5 void insertion_sort( int * arr, int size) { 6 int i , j, key; 7 for ( i = 1; i < size; i ++ ) { 8 key = arr[i]; 9 j = i - 1; 10 while ( arr[j] > key && j >= 0 ) { 11 arr[j + 1] = arr[ j ]; 12 j = j - 1; 13 } 14 arr[ j + 1 ] = key; 15 } 16 } 17 18 int main( int argc, char **argv) { 19 int k, ans = 0, i ; 20 scanf("%d",&k); 21 for ( i = 0; i < k ; i ++) 22 scanf("%d",&group_distribution[i]); 23 insertion_sort(group_distribution, k); 24 for ( i = 0; i < (k+1)/2 ; i++ ) { 25 ans += (group_distribution[0]+1)/2 ; 26 } 27 printf("%d\n",ans); 28 return 0; 29 } ``` |
Wrong answer! Test 5 is failed. Python | Quietude | 1025. Демократия в опасности | 20 сен 2018 00:29 | 2 |
n = int(input()) l = list(map(int, input().split())) l1 = [] for i in range(n): l1.append((l[i]//2 +1)) if n > 3: k = (n // 2 + 1) // 2 + 1 #Groups which decline else: k = (n // 2 + 1) // 2
for i in range(k): l1.remove(max(l1)) print(sum(l1)) Edited by author 15.09.2018 21:04 Just simplify ur code. This is very easy task. Bellow there is my ac solution: [code deleted] Edited by moderator 20.11.2019 00:09 |
WA test#3 what is the problem?? | sj alim | 1025. Демократия в опасности | 16 июл 2018 02:36 | 1 |
#include<stdio.h> int main() { int n,i,j,item[9999],a,sum=0,temp; scanf("%d",&n); for(i=0; i<n; i++) scanf("%d",&item[i]); for(j=1; j<n; j++) for(a=n-1; a>=j; a--) { if(item[a-1]>item[a]) { temp=item[a-1]; item[a-1]=item[a]; item[a]=temp; } } for(i=0; i<((n+1)/2); i++) { sum=sum+(item[a]+1)/2; } printf("%d\n",sum); return 0; } |
How you've get 0.001 ? | KOTnt | 1025. Демократия в опасности | 29 окт 2017 14:31 | 4 |
Tell me please how you have get timing 0.001 ? It mustn't be a code, may be just method or algorithm. Thanks I think it's impossible to get time less than 0,015 sec at new testing system (since approx. end of 2008). Look at problem 1000 - simple operation, but you can't now get time less than 0.015 neither on C++ nor on Pascal. Furthermore, step between time measurment is about 0,016 (so you can get 0,015 or 0,031 but nothing between) And furthermore, when you run you some hard solution sequental some times, it will get significant different time result. For example, my Pascal AC solution for 1001 sended a few of times takes 0.078, 0.093 or 0.109 sec I think it because mistake in time-measurment method. I think they using a system-clock (RTC) that renew after significant time. So, if testing system is hard loaded (for example testing many authors in parallel) the testing will take more time relatively ro Real-Time Clock, than when system is idle (at early morning, for example). So, testing system is incorrect and you can't reach time less than 0.015 until realisation of system will be changed Excuse my English I understood, thank you ) Your English is OK My code runtime is 0.001. If you use bitwise operation your code will get AC in 0.001. Here is my code. If you want you can learn. [code deleted] Edited by moderator 20.11.2019 00:08 |
I didn't Understand the solution | Iamyeasin | 1025. Демократия в опасности | 29 окт 2017 14:10 | 1 |
If I divide first and then add 1 with (n or other group numbers), I get WA. But if I add 1 at first and then I divide that time i get AC. I have seen some of the discussion, but couldn't find the logic.Can someone help me out? |
Use heap. Use number 0.5*K+1. | Mahilewets | 1025. Демократия в опасности | 17 июн 2017 01:05 | 1 |
|
где ошибка? | Nick | 1025. Демократия в опасности | 10 дек 2016 03:24 | 3 |
using System; class Program { static void Main() { int t = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); Array.Sort(s); int r = 0; for (int i = 0; i < (t / 2)+1; i++) { r += ((int.Parse(s[i]) / 2) +1); } Console.WriteLine(r); } } Edited by author 16.06.2012 19:10 Edited by author 16.06.2012 19:11 You must input all the array first, and only then work with it Edited by author 10.12.2016 03:26 |
I don't know where is wrong. ( Pascal ) | Babin Alexander | 1025. Демократия в опасности | 14 окт 2016 22:41 | 2 |
Wrote on Pascal: var i, j: integer; ms, a, b: integer; arrg: array of integer; begin Read(ms); SetLength(arrg, ms);
for i := 0 to arrg.Length - 1 do begin var temp: integer; Read(temp); arrg[i] := temp; end;
for j := 1 to arrg.Length - 1 do for i := 1 to arrg.Length - j do if arrg[i - 1] > arrg[i] then Swap(arrg[i - 1], arrg[i]);
a := arrg.Length div 2;
for i := 0 to a do b := b + arrg[i] div 2 + 1;
Write(b); end. Wrong answer ( test 1 ). arrg.Length it may be odd |
Why Compilation error? | vladi_pavloff | 1025. Демократия в опасности | 27 мар 2016 00:53 | 2 |
var t: real; n, k, i,j: integer; a:array [1..101] of integer; begin readln(n); for i := 1 to n do begin read(a[i]); end; for i:=1 to n do begin for j:=1 to n do begin if a[i]<a[j] then begin swap(a[i],a[j]); end; end; end;
for i:=1 to (n div 2)+1 do begin t:=t+((a[i] div 2)+1); end;
write(t); end. Pascal hasn't function swap. You should to write it yourself |
My code showing Run time error Non zero exit code. Why? | Md johirul Islam | 1025. Демократия в опасности | 30 май 2015 01:08 | 1 |
import java.util.Arrays; import java.util.Scanner; public class T1025 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int k=sc.nextInt(); int [] a=new int[k]; for(int i=0;i<k;i++) { a[i]=sc.nextInt(); } Arrays.sort(a); int vote=0; int mid=k%2==0?k/2:k/2+1; for(int i=0;i<mid;i++) { vote+=a[i]/2+1; } System.out.println(vote); } } |
1025 WA#2 (C) | kh1024 | 1025. Демократия в опасности | 27 янв 2015 05:35 | 2 |
Issue resolved, see below! Edited by author 27.01.2015 05:49 So, be careful if manually calculating - subtle fact is that the aggregate majority of a sequence of numbers may not actually represent the majority from each individual group, for example (from another thread): 5 5 5 5 5 5 => 9 But at first, I naively calculated (5+5+5)/2 + 1, which works in other group sizes but not for duplicate numbers. So, just keep that in mind :) Edited by author 27.01.2015 05:49 |