A enter an array where the elements of the array can be exchanged only once, and the maximum distance between the maximum and minimum values is calculated. (later found to see the topic is not serious, the minimum value is 1, the maximum value is n ...)
#include <iostream>#include<cstring>#include<algorithm>using namespacestd;intnum[ the];intMain () {intN; while(cin>>N) {intmmax=-1, mmin=Ten, maxflag=-1, minflag=-1; memset (num,0,sizeof(num)); for(intI=0; i<n;i++) {cin>>Num[i]; } for(intI=0; i<n;i++) { if(num[i]>Mmax) {Mmax=Num[i]; Maxflag=i; } if(num[i]<mmin) {Mmin=Num[i]; Minflag=i; } } intTemp=max (Max (n1-minflag,max (Minflag,maxflag)), N-1-Maxflag); cout<<temp<<Endl; } return 0;}View Code
B Simulation (This question is a double problem, always feel that sooner or later in the accuracy of the loss, so the first thought to enlarge the corresponding multiples ...)
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;Doubleglass[ the][ the];intMain () {intn,t; while(~SCANF ("%d%d",&n,&t) {memset (glass,0,sizeof(glass)); glass[1][1]=T; intCnt=0; for(intI=1; i<=n;i++) { for(intj=1; j<=i;j++) { if(glass[i][j]>=1) cnt++; if(glass[i][j]>1) {glass[i+1][j]+= (glass[i][j]-1)/2; Glass[i+1][j+1]+= (glass[i][j]-1)/2; }}} printf ("%d\n", CNT); } return 0;}View Code
CF Round #354 (Div.2)