Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:为什么两个代码感觉只是时间上会稍微有点差别,却一个是WA,一个是AC,而不报TLE?????In Reply To:为什么两个代码感觉只是时间上会稍微有点差别,却一个是WA,一个是AC,而不报TLE????? Posted by:nuciedh at 2007-02-13 13:32:19 > 这个WA: > #include <iostream> > #include <fstream> > const int N = 100010; > > using namespace std; > > int n, k, a[N]; > > int attempt (int l, int r) > { > int i, b, t, s; > int tmp; > if (l < r) > { > s = 0; > t = (l + r) / 2; > for (i = 0; i < n; i ++) > { > tmp = a[i]; > tmp -= t; > if (tmp > 0) > { > s += (tmp + k - 2) / (k - 1); > } > } > if (s <= t) > { > b = attempt (l, t); > } > else > { > b = attempt (t + 1, r); > } > return b; > } > else > { > return r; > } > } > > void solve () > { > int i, tmp; > for (tmp = 0, i = 0; i < n; i ++) > { > scanf ("%d", &a[i]); > if (a[i] > tmp) > { > tmp = a[i]; > } > } > scanf ("%d", &k); > if (k > 1) > { > printf ("%d\n", attempt (1, tmp)); > } > else > { > printf ("%d\n", tmp); > } > } > > int main () > { > while (EOF != scanf ("%d", &n)) > { > solve (); > } > return 0; > } > > 这个AC: > #include <iostream> > #include <fstream> > const int N = 100010; > > using namespace std; > > int n, k, a[N]; > > int attempt (int l, int r) > { > int i, b, t, s; > int tmp; > if (l < r) > { > s = 0; > t = (l + r) / 2; > for (i = 0; i < n; i ++) > { > tmp = a[i]; > tmp -= t; > if (tmp > 0) > { > s += tmp / (k - 1); > if ((tmp % (k - 1)) != 0) > { > s ++; > } > if (s > t) > { > break; > } > } > } > if (i >= n) > { > b = attempt (l, t); > } > else > { > b = attempt (t + 1, r); > } > return b; > } > else > { > return r; > } > } > > void solve () > { > int i, tmp; > for (tmp = 0, i = 0; i < n; i ++) > { > scanf ("%d", &a[i]); > if (a[i] > tmp) > { > tmp = a[i]; > } > } > scanf ("%d", &k); > if (k > 1) > { > printf ("%d\n", attempt (1, tmp)); > } > else > { > printf ("%d\n", tmp); > } > } > > int main () > { > while (EOF != scanf ("%d", &n)) > { > solve (); > } > return 0; > } > > > > > > > > > > > > > > Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator