Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
Страница 4 |
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 |
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 |
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. |
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 |
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; } |
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 |
|
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 |
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); } } На этот вопрос есть где-нибудь ответ? У меня другой код, та же ошибка. ( |
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 |
What's in test 5? | _Link | 1025. Демократия в опасности | 23 мар 2014 18:24 | 2 |
What numbers could be in test 5? Everything is right. Why it doesn't accepted... Сомневаюсь, что кто-то ответит, но мало ли Ну же... Хоть кто нибудь Спать не могу |
acmp | Abdulkhakim | 1025. Демократия в опасности | 22 май 2014 15:12 | 3 |
acmp Abdulkhakim 15 янв 2014 14:54 why this is accepted but in the acmp wrong answer 2 461 in acmp Edited by author 15.01.2014 14:54 Because there numbers may be even. Re: acmp Smilodon_am [Obninsk INPE] 22 май 2014 15:12 Restrictions on number K are different |
Страница 3 |
Compilation error | Evgeniy_Chernobrovkin(MUCTR-2013) | 1025. Демократия в опасности | 26 сен 2013 03:01 | 1 |
#include "stdafx.h" #include <iostream> #include <conio.h> using namespace std; void bubbleSort(int array[], int col){ int temp=0; for (int i=1; i<col ; i++){ for (int j=0; j<col-i; j++){ if (array [j]>array [j+1]){ temp=array[j]; array [j]=array [j+1]; array [j+1]=temp; } } } } int _tmain(int argc, _TCHAR* argv[]) { int k; int max; int sum; sum = 0; max = 0; cin >> k; int *p = new int[k-1]; int i; for (i = 0; i < k; i++) { cin >> p[i]; }
bubbleSort(p, k-1); k=k/2+1; for (i=0; i<k; i++) { sum = sum + p[i]/2+1; } cout << sum; _getch(); return 0; } kgxvh8-ov2fjo kgxvh8-ov2fjo(1) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory What's wrong? There is no problem in Visual Studio 12 :( |
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?. |
what is wrong in my code (WA №2)? | Alexandr Zhelanov | 1025. Демократия в опасности | 29 окт 2014 14:42 | 4 |
What is wrong in my code? Please, give me a hint. var k,i,min,max,voices,sum:integer; ka:array [1..101] of integer; begin readln(k); for i:= 1 to k do begin read(ka[i]); if i=1 then begin min:=ka[i]; max:=ka[i]; end else begin if ka[i]<min then min:=ka[i]; if ka[i]>max then max:=ka[i]; end; end;
if min<>max then begin for i:=1 to k do begin if ka[i]=min then sum:=sum+ka[i]; end; voices:=sum div 2 +1; end else begin for i:=1 to k do sum:=sum+ka[i]; voices:=sum div 2 +1; end;
writeln(voices); end. |