1 solutions
-
0
C++ :
#include<iostream> #include<bits/stdc++.h> using namespace std; int a[201],b[201],ans[201]; int n,i,j,tmp; int main() { cin >> n; for(i = 1; i <= n; i++) cin >> a[i] >> b[i]; for(i = 1; i < n; i++) for(j = i + 1; j <= n; j++) if(a[i] < a[j] || a[i] == a[j] && b[i] > b[j]) { tmp = a[i]; a[i] = a[j]; a[j] = tmp; tmp = b[i]; b[i] = b[j]; b[j] = tmp; } ans[1] = 0; for(i = 2; i <= n; i++) { ans[i] = 0; for(j = 1; j < i; j++) if(b[i] > b[j]) ans[i]++; } for(i = 1; i <= n; i++) cout << ans[i] << endl; return 0; }Pascal :
var s,g:array[1..200] of longint; i,j,n,ans:longint; procedure qsort(l,r:longint); var i,j,t,mid1,mid2:longint; begin i:=l; j:=r; mid1:=s[(i+j) div 2]; mid2:=g[(i+j) div 2]; repeat while (s[i]>mid1) or (s[i]=mid1) and (g[i]<mid2) do inc(i); while (s[j]<mid1) or (s[j]=mid1) and (g[j]>mid2) do dec(j); if i<=j then begin t:=s[i]; s[i]:=s[j]; s[j]:=t; t:=g[i]; g[i]:=g[j]; g[j]:=t; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; begin readln(n); for i:=1 to n do readln(s[i],g[i]); qsort(1,n); for i:=1 to n do begin ans:=0; for j:=1 to i-1 do if g[j]<g[i] then inc(ans); writeln(ans); end; end.
- 1
Information
- ID
- 16685
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By