#include<iostream> #include<vector> using namespace std; int main() { int k; cin>>k; vector<int> p; for(int i=0,a=0;i<k;i++) {cin>>a; p.push_back (a); } for(int temp=0,j=0;j<k-1;j++) { if(p[j]>p[j+1]) { temp=p[j]; p[j]=p[j+1]; p[j+1]=temp; } }
int out=0; for(int b=0;b<=k/2;b++) out=out+p[b]/2+1; cout<<out<<"\n"; return 0; } [code deleted] Edited by moderator 20.11.2019 00:22 qsort((void*)a,i,sizeof(int),sort); -> qsort((void*)a,n,sizeof(int),sort); 0.001 142 КБ You real-true-mega-shguzhii coder ! How you write this program? let a[i] stand for the member of party i; sort it to make a[1]<a[2]<...<a[n] for i:=1 to (k+1) div 2 do inc(answer,(a[i]+1) div 2); the answer is sure to be the best one. I have such sing too,but say me how you write this program I don't understood! Where different in Pascal 1) round(k/2) and 2) (k+1) div 2 with 1) - WA#1 with 2) - AC Edited by author 09.06.2006 18:41 Edited by author 09.06.2006 18:41 Edited by author 09.06.2006 18:41 probably, not round(k/2), but trunc(k/2) No, not trunc(k/2). For example, if k=5, round(k/2)=2 (k+1) div 2=3. Edited by author 23.06.2006 13:22 Why (k+1) div 2 ?? Write (k) div 2 and it'll be ok. I wrote g:=g + (a[i] div 2 + 1) because we have to take more than half. For example : if a[i] = 5 then majority will be 3, and 3 we can get only using this expression g:=g + (a[i] div 2 + 1) Solutions that earlier got AC now get wa3. I think that 3rd test was modified according to the problem statement (recently 10001 was changed to 9999), but answer was left old. 1. и решение вопрос решался положительно в том и только том случае -> и вопрос решался положительно в том и только том случае 2. проводить некоторые решения не обладая при этом -> проводить некоторые решения, не обладая при этом 3. население острова не превосходит 10001 человек -> население острова не превосходит 10001 человека #include <iostream> using namespace std; int main() { bool t; int n,nn; cin>>n; short a[n]; for(int i=0;i<n;i++) { t=true; cin>>nn; if((i-1>=0&&a[i-1]<=nn)||(i==0)) a[i]=nn; else for(int j=0;j<i;j++) { if(a[j]>nn) { for(int jj=i;jj>j;jj--) a[jj]=a[jj-1]; a[j]=nn; t=false; } if(!t)break; } } int c=0; for(int i=0;i<(n/2)+1;i++) c+=a[i]/2+1; cout<<c; } compiling error?? Edited by author 07.10.2007 21:56 [code deleted] Edited by moderator 20.11.2019 00:23 AC!you must create your array with another way var c:array [1..101] of integer; i,k,j,kol,d:integer; begin kol:=0; read(k); for i:=1 to k do read(c[i]); for j:= k-1 downto 2 do for i:= 1 to j do if (c[i]>c[i+1]) then begin d:=c[i]; c[i]:=c[i+1]; c[i+1]:=d; end; k:=round(k/2); for i:=1 to k do kol:=kol+round(c[i]/2); write(kol); end. hi I don't understand why this is not good for test 1 . I obtain WA. Who can tell me what is not good. import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.*; public class Main { public static void main(String[] args) { int nr = 0; int i; int suma=0; try { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); nr = Integer.parseInt(stdin.readLine()); int []v = new int[nr]; Scanner scan = new Scanner(System.in); for (i=0;i<nr;i++) { v[i]= scan.nextInt(); } Arrays.sort(v); nr=nr/2+1; int n=0; for (i=0;i<nr;i++) { n=v[i]; suma=suma+((n/2)+1); } System.out.println(suma); } catch (Exception e) { e.getMessage(); } } } thanx this is a simple question about sorting. You need to find the least voters that can make the voting valid. hint: you need to get more than half voters in each group and you need more than half of all the groups. i did exactly what u said still getting WA i have tried this with heap,bubble and insertion sort. Even i tried using sorted link list. then i tried this without any sorting with arrays. still my time limit is exceeding for test 1 . please give me some hints. the timel limit is not because of sorting. the bubble sort must work fast enough you can show me your code and i will find your bug twoalias@inbox.ru i have omitted the bug of exceeding time limit. but now it says wrong answer. can anybody provide me some test cases please ? In DevC++ program compile perfect; And it works; but why isn't working in here :[ Please help me... #include<iostream> using namespace std; int main(){ int k,grup[101]; cin >> k; int majority = k/2+1, min[majority],sum=0; for(int i=0;i<k;i++) cin >> grup[i]; int localMin=grup[0], indx=0,H=0; while(H<majority){ for(int i=1;i<k;i++){ if((grup[i]<localMin)&&(grup[i]>0)){ localMin=grup[i]; indx=i; } } min[H]=localMin/2+1; grup[indx]=-2; H++; } for(int i=0;i<majority;i++) sum += min[i];
cout << sum << endl; } i think there isnt any error...................... error: expression must have a constant value int majority = k/2+1, min[majority],sum=0; ^ int min[250]; int majority = k/2+1,sum=0; Edited by author 03.09.2007 23:00 Hi. I've made a silly mistake (my algorithm calculated everything based only on the number of people in 1st group), so I got WA but only on test #5. I cant understood.............. e-mail:pirat_golden@hotmail.com #include "stdio.h" int main () { long n,total; long i,j; long zz; long a[1000];
scanf ("%ld",&n); for (i=1;i<=n;) { scanf ("%ld",&a[i]); if (a[i]%2!=0) i++; } for (i=1;i<=n;i++) for (j=i+1;j<=n;j++) if (a[i]>a[j]) { zz=a[j]; a[i]=a[j]; a[j]=zz; } total=0; for (i=1;i<=n/2+1;i++) total=total+a[i]/2+1; printf ("%ld",total); return (0); } zz=a[i]; !!! Edited by author 11.12.2006 19:25 Thank you very much,I've just had a silly wrong! i want to know what is test5. var i, j, k, t: word; a: array [1 .. 101] of word; s: word; begin read(k); if k = 0 then s := 0 else begin for i := 1 to k do read(a[i]); for i := 1 to k - 1 do for j := 1 to k - i do if a[j] > a[j + 1] then begin t := a[j]; a[j] := a[j + 1]; a[j + 1] := t; end; s := 0; for i := 1 to k div 2 + 1 do s := s + a[j] div 2 + 1; end; writeln(s); end. Here is my program! IT works. const kmax = 101; var n, n2, k, t, i, j: longint; a: array[1..kmax] of longint; begin read(k); for i := 1 to k do read(a[i]); for i := 1 to k - 1 do for j := 1 to k - i do if a[j] > a[j + 1] then begin t := a[j]; a[j] := a[j + 1]; a[j + 1] := t; end; n := 0; for i := 1 to k div 2 + 1 do inc(n, a[i] div 2 + 1); write(n); end. Plz help me, i not understand why i have WA. #include <stdio.h> int main() { int i,j=0,tmp,real; int K; int wantnum=0; int grp[101]; scanf("%d",&K); for(i=0; i<K; i++) { scanf("%d",&tmp); if((tmp%2 == 0)) continue; grp[j] = tmp; j++; } real=j; for(i=0; i<K; i++) for(j=0; j<K-i; j++) if(grp[j] > grp[j+1]) { tmp=grp[j]; grp[j]=grp[j+1]; grp[j+1]=tmp; } for(i=0; i<real/2+1; i++) wantnum += grp[i]/2+1; printf("%d",wantnum); return 0; } your bubble sort is not working right. add -1 on the second for check for(i=0; i<K; i++) for(j=0; j<K-i - 1; j++) if(grp[j] > grp[j+1]) { tmp=grp[j]; grp[j]=grp[j+1]; grp[j+1]=tmp; } sorry for my english :P Plz help me, i not understand why i have WA. #include <stdio.h> int main() { int i,j=0,tmp,real; int K; int wantnum=0; int grp[101]; scanf("%d",&K); for(i=0; i<K; i++) { scanf("%d",&tmp); if((tmp%2 == 0)) continue; grp[j] = tmp; j++; } real=j; for(i=0; i<K; i++) for(j=0; j<K-i; j++) if(grp[j] > grp[j+1]) { tmp=grp[j]; grp[j]=grp[j+1]; grp[j+1]=tmp; } for(i=0; i<real/2+1; i++) wantnum += grp[i]/2+1; printf("%d",wantnum); return 0; } Plz help me, i not understand why i have WA. #include <stdio.h> int main() { int i,j=0,tmp,real; int K; int wantnum=0; int grp[101]; scanf("%d",&K); for(i=0; i<K; i++) { scanf("%d",&tmp); if((tmp%2 == 0)) continue; grp[j] = tmp; j++; } real=j; for(i=0; i<K; i++) for(j=0; j<K-i; j++) if(grp[j] > grp[j+1]) { tmp=grp[j]; grp[j]=grp[j+1]; grp[j+1]=tmp; } for(i=0; i<real/2+1; i++) wantnum += grp[i]/2+1; printf("%d",wantnum); return 0; } Why 2 ABSOLUTELY ideintific soulutions gets different results? Pascal get AC, C gets WA test 5 :(. |
|