2019-04-19 22:44:49 C

C

Copy Copied! Full
#include <stdio.h> #include <stdlib.h> int cmp(const void*a,const void*b){ return *(int*)a-*(int*)b; } int main(void){ int n,i,d,f,ans=0; scanf("%d",&n); int a[n],b[n],c[n]; for(i=0;i<n;i++)scanf("%d",&a[i]); for(i=0;i<n;i++)scanf("%d",&b[i]); for(i=0;i<n;i++)scanf("%d",&c[i]); qsort(a,n,sizeof(int),cmp); qsort(b,n,sizeof(int),cmp); qsort(c,n,sizeof(int),cmp); int func1(int x){ int ok = 0;//解が存在する値 int ng = n;//解が存在しない値 int mid=0; while(abs(ok-ng)>1){ mid = (ok+ng)/2; if(x>a[mid]){ ok = mid; }else{ ng = mid; } } return mid; printf("mid = %d\n",mid); } int func2(int x){ return n; } for(i=0;i<n;i++){ d = func1(b[i]); f = func2(b[i]); ans += d*f; } return 0; }