|
|
вернуться в форумhelp me , please ! Послано snack 1 дек 2008 18:21 #include <iostream> #include <algorithm> #include <cmath> #define ford(i,n) for (long i=1; i<=n; i++) #define openfile freopen("1306.in4","r",stdin); #define closefile freopen("out1.txt","w",stdout); using namespace std; const long maxn=130000; long long n,a[maxn],x; long long m,l; void xuly1() { ford(i,n/2+1) { cin >> a[i]; push_heap(&a[1],&a[i+1]); } for(int i=n/2+2; i<=n ; i++) { cin >> x; if (x==a[1]) { a[n/2+1]=a[1]; push_heap(&a[1],&a[n/2+2]); } else if (x<a[1]) { pop_heap(&a[1],&a[n/2+2]); a[n/2+1]=x; push_heap(&a[1],&a[n/2+2]); } } x=a[1]; pop_heap(&a[1],&a[n/2+2]); m=x; l=a[1]; cout << (m+l)/2 ; m=(m+l) % 2 ; if (m==1) cout << ".5" << "\n"; else cout << ".0" << "\n"; } void xuly2() { ford(i,(n+1)/2) { cin >>a[i]; push_heap(&a[1],&a[i+1]); } for(int i=(n+1)/2+1; i<=n ; i++) { cin >> x; if (x<a[1]) { pop_heap(&a[1],&a[(n+1)/2+1]); a[(n+1)/2]=x; push_heap(&a[1],&a[(n+1)/2+1]); } } cout << a[1] <<".0"<< endl; } int main() { // openfile; closefile; cin >> n; if (n % 2==0) xuly1() ; else xuly2(); cin >> n; return 0; } Re: help me , please ! Послано snack 1 дек 2008 18:22 WA in #4 , i do not know the cause. #include <iostream> #include <algorithm> #include <cmath> #define ford(i,n) for (long i=1; i<=n; i++) #define openfile freopen("1306.in4","r",stdin); #define closefile freopen("out1.txt","w",stdout); using namespace std; const long maxn=130000; long long n,a[maxn],x; long long m,l; void xuly1() { ford(i,n/2+1) { cin >> a[i]; push_heap(&a[1],&a[i+1]); } for(int i=n/2+2; i<=n ; i++) { cin >> x; if (x==a[1]) { a[n/2+1]=a[1]; push_heap(&a[1],&a[n/2+2]); } else if (x<a[1]) { pop_heap(&a[1],&a[n/2+2]); a[n/2+1]=x; push_heap(&a[1],&a[n/2+2]); } } x=a[1]; pop_heap(&a[1],&a[n/2+2]); m=x; l=a[1]; cout << (m+l)/2 ; m=(m+l) % 2 ; if (m==1) cout << ".5" << "\n"; else cout << ".0" << "\n"; } void xuly2() { ford(i,(n+1)/2) { cin >>a[i]; push_heap(&a[1],&a[i+1]); } for(int i=(n+1)/2+1; i<=n ; i++) { cin >> x; if (x<a[1]) { pop_heap(&a[1],&a[(n+1)/2+1]); a[(n+1)/2]=x; push_heap(&a[1],&a[(n+1)/2+1]); } } cout << a[1] <<".0"<< endl; } int main() { // openfile; closefile; cin >> n; if (n % 2==0) xuly1() ; else xuly2(); cin >> n; return 0; } |
|
|