标签:des style blog http color io os java ar
哎,注意细节啊,,,,,,,思维的严密性。。。。。
11699193 | 2014-09-22 08:46:42 | Accepted | 5037 | 796MS | 1864K | 2204 B | G++ | czy |
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 454 Accepted Submission(s): 96
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<map> 9 #include<string> 10 11 #define N 200005 12 #define M 15 13 #define mod 10000007 14 //#define p 10000007 15 #define mod2 100000000 16 #define ll long long 17 #define LL long long 18 #define maxi(a,b) (a)>(b)? (a) : (b) 19 #define mini(a,b) (a)<(b)? (a) : (b) 20 21 using namespace std; 22 23 int T; 24 int n; 25 int m,l; 26 int dp[N]; 27 int p[N]; 28 29 void ini() 30 { 31 memset(dp,0,sizeof(dp)); 32 scanf("%d%d%d",&n,&m,&l); 33 for(int i=1;i<=n;i++){ 34 scanf("%d",&p[i]); 35 } 36 sort(p+1,p+1+n); 37 p[n+1]=m; 38 } 39 40 41 void solve() 42 { 43 int sh; 44 int te; 45 int now; 46 int end; 47 int d; 48 int tnow; 49 now=0; 50 d=1; 51 for(int i=1;i<=n+1;){ 52 dp[i]=dp[i-1]; 53 te=(p[i]-now); 54 sh=te/(l+1); 55 dp[i]+=sh*2+1; 56 if(te%(l+1)!=0){ 57 //dp[i]--; 58 // if(sh!=0 && te%(l+1)<d){ 59 // dp[i]--; 60 // tnow=now+(sh-1)*(l+1)+d; 61 // end=tnow+l; 62 // now=p[i]; 63 64 // } 65 // else{ 66 now=now+sh*(l+1); 67 tnow=now; 68 end=tnow+l; 69 now=p[i]; 70 // } 71 72 i++; 73 while(i<=n+1 && p[i]<=end){ 74 dp[i]=dp[i-1]; 75 now=p[i]; 76 i++; 77 } 78 d=l+1-(now-tnow); 79 } 80 else{ 81 dp[i]--; 82 tnow=now+(sh-1)*(l+1)+d; 83 end=tnow+l; 84 now=p[i]; 85 i++; 86 while(i<=n+1 && p[i]<=end){ 87 dp[i]=dp[i-1]; 88 now=p[i]; 89 i++; 90 } 91 d=l+1-(now-tnow); 92 } 93 } 94 } 95 96 void out() 97 { 98 printf("%d\n",dp[n+1]); 99 } 100 101 int main() 102 { 103 //freopen("data.in","r",stdin); 104 //freopen("data.out","w",stdout); 105 scanf("%d",&T); 106 for(int cnt=1;cnt<=T;cnt++) 107 // while(T--) 108 // while(scanf("%d%d",&n,&m)!=EOF) 109 { 110 // if(n==0 && m==0) break; 111 printf("Case #%d: ",cnt); 112 ini(); 113 solve(); 114 out(); 115 } 116 117 return 0; 118 }
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/njczy2010/p/3985370.html