A场:求最大分离度
这道题做错了,3分
#include <iostream> #include <algorithm> using namespace std; int cmp( int arg1, int arg2 ) { return arg1 > arg2; } int main(int argc, char* argv[]) { //freopen("i://input.txt","r",stdin); int n,m; int i; scanf("%d %d",&n,&m); int *marr = new int[m]; for(i=0;i<m;i++){ scanf("%d",&marr[i]); } sort(marr,marr+m,cmp); int sum = 0; int lastIndex = m - 1; int lastRowNum = 0; while(1){ sum +=(marr[lastIndex]-1)*m*m+lastRowNum*m; lastRowNum = m; for(i = 0;i<=lastIndex;i++){ marr[i] -= marr[lastIndex]; } while(marr[lastIndex]==0&&lastIndex>=0){m--;lastIndex--;} if(m==0)break; } printf("%d\n",sum); delete marr; return 0; }
B场:两道题得12分
第一题:圆环
#include <iostream> #include <algorithm> using namespace std; int arr[1001]; int cmp( int arg1, int arg2 ) { return arg1 > arg2; } int qcmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } int next(int curr,int length,int tap){ return tap-(length-curr)%tap; } bool canChangeTo1(int length,int tap){ int cur =1; for(int i=0;i<tap;i++){ cur=next(cur,length,tap); if(cur==2||cur==tap) return true; } return false; } int main(int argc, char* argv[]) { int c; while(1==scanf("%d",&c)&&c){ int a,b,i; bool ok = false; bool end = false; scanf("%d%d",&a,&b); int tap = a-b; tap = tap<0?(-tap):tap; if(tap==1){ ok = true; end = true; }else{ if(canChangeTo1(c,tap)){ ok = true; end = true; } } for(i=0;i<c;i++) scanf("%d",arr+i); if(!end){ for(i=0;i<tap;i++) qsort(arr+i,(c-i)/tap+1,sizeof(arr[0])*2,qcmp); ok = true; for(i=0;i<c-1;i++) if(arr[i]>arr[i+1]){ end = true; ok = false; break; } } printf("%s\n",ok?"Yes":"No"); } return 0; }
第三题:全暴力
#include <iostream> #include <math.h> #include <algorithm> using namespace std; int Gcw(int ,int ); void simply(int *up,int *down) { int gcw = -1; while( (gcw = Gcw(*up,*down)) != -1 ) { *up = *up/gcw; *down = *down/gcw; } } int Gcw(int u, int v) { if (!(u = u%v)) return v; if (u == 1) return -1; return Gcw(v,u); } int main(int argc, char* argv[]) { int t,n;//total , need int i; double maxSatisfy = -1.0; int up,down; scanf("%d%d",&t,&n); int *arr = new int[t]; for(i=0;i<t;i++) scanf("%d",arr+i); for(int c = n;c<=t;c++){ for(int j = 0;j<t;j++){ if(j+c>t)break; int temp = 0; for(int k=0;k<c;k++) { temp+=arr[k+j]; } double newSati = temp/(c*1.0); if(newSati>maxSatisfy){ maxSatisfy = newSati; up = temp; down = c; } } } if(up%down == 0)printf("%d\n",up/down); else { simply(&up,&down); printf("%d/%d\n",up,down); }
delete arr;
return 0;
}