第5次周赛

不想说自己了,太不在状态了,各种白痴错误,纠结一个破离散化,DP的类型看错了,复杂度算错了……各种悲剧

A水题不解释

HDU 3449

是个背包,开始由于数据范围看错了,当树形背包做的,其实很水的背包题dp[i][2][j] 的状态,要用long long

爆内存,要用滚动数组……

HDU 3449
1 #include < iostream >
2 #include < cstring >
3 #include < cstdio >
4   using namespace std;
5   const int W = 100001 ;
6   long long dp[ 2 ][ 2 ][W];
7   int main()
8 {
9 int n, w, p, vi, wi, m;
10 while (scanf( " %d %d " , & n, & w) == 2 )
11 {
12 memset(dp, - 1 , sizeof (dp));
13 dp[ 0 ][ 0 ][ 0 ] = 0 ;
14 for ( int i = 1 ;i <= n;i ++ )
15 {
16 scanf( " %d %d " , & p, & m);
17 for ( int j = 0 ;j <= w;j ++ )
18 {
19 if (j + p <= w)
20 dp[ 1 ][ 1 ][j + p] = max(dp[ 1 ][ 1 ][j + p], max(dp[ 0 ][ 0 ][j], dp[ 0 ][ 1 ][j]));
21 dp[ 1 ][ 0 ][j] = max(dp[ 1 ][ 0 ][j], max(dp[ 0 ][ 0 ][j], dp[ 0 ][ 1 ][j]));
22 }
23 while (m -- )
24 {
25 scanf( " %d %d " , & wi, & vi);
26 for ( int j = w;j >= wi;j -- )
27 {
28 if (dp[ 1 ][ 1 ][j - wi] != - 1 )
29 dp[ 1 ][ 1 ][j] = max(dp[ 1 ][ 1 ][j], dp[ 1 ][ 1 ][j - wi] + vi);
30 }
31 }
32 for ( int j = 0 ;j <= w;j ++ )
33 {
34 dp[ 0 ][ 0 ][j] = dp[ 1 ][ 0 ][j];
35 dp[ 0 ][ 1 ][j] = dp[ 1 ][ 1 ][j];
36 dp[ 1 ][ 0 ][j] = dp[ 1 ][ 1 ][j] = - 1 ;
37 }
38 }
39 long long ans = 0 ;
40 for ( int i = 0 ;i <= w;i ++ )
41 ans = max(ans, max(dp[ 0 ][ 1 ][i], dp[ 0 ][ 0 ][i]));
42 printf( " %lld\n " , ans);
43 }
44 return 0 ;
45 }

HDU 2448 搜索题,不解释自己多白痴了……不过我很讨厌这样的题,1是剪枝的理由总是不那么充分可能是和数据有关……

HDU 3448
1 #include < iostream >
2 #include < cstring >
3 #include < cstdio >
4 #include < algorithm >
5 using namespace std;
6
7 const int N = 41 ;
8 long long w[N], ans;
9 long long m;
10 int n, k;
11 void dfs( int x, long long s, int cnt)
12 {
13 if (cnt > k || s > m) return ;
14 ans = max(ans, s);
15 if (x >= n) return ;
16 for ( int i = x + 1 ;i < n;i ++ )
17 dfs(i ,s + w[i], cnt + 1 );
18 }
19
20 int main()
21 {
22 while (scanf( " %d %lld " , & k, & m) == 2 )
23 {
24 scanf( " %d " , & n);
25 long long s = 0 ;
26 for ( int i = 0 ;i < n;i ++ )
27 {
28 scanf( " %lld " , & w[i]);
29 }
30 sort(w, w + n);
31 for ( int i = n - 1 ;i >= n - k;i -- )
32 s += w[i];
33 if (s <= m)
34 printf( " %lld\n " , s);
35 else if (w[ 0 ] > m)
36 printf( " 0\n " );
37 else
38 {
39 ans = 0 ;
40 dfs( - 1 , 0 , 0 );
41 printf( " %lld\n " , ans);
42 }
43 }
44 return 0 ;
45 }

HDU 3450

我写数据结构就是一个悲剧……也就在这里鄙视一下自己吧

HUD 3450
1 #include < iostream >
2 #include < cstdio >
3 #include < cstring >
4 #include < algorithm >
5 #include < cassert >
6 #include < set >
7 using namespace std;
8 const int N = 1000111 ;
9 const int MOD = 9901 ;
10 int a[N], c[N], b[N * 3 ], idx[N * 3 ];
11
12 int mod( int a, int MOD)
13 {
14 return (a % MOD + MOD) % MOD;
15 }
16
17 int lowbit( int k)
18 {
19 return k & ( - k);
20 }
21
22 int sum( int pos)
23 {
24 if (pos == 0 ) return 0 ;
25 int s = 0 ;
26 for ( int i = pos; i > 0 ; i -= lowbit(i))
27 s = (s + c[i]) % MOD;
28 return s;
29 }
30
31 void modify( int pos, int x)
32 {
33 for ( int i = pos; i < N; i += lowbit(i))
34 c[i] = (c[i] + x) % MOD;
35 }
36
37 int binary_search( int low, int high, int x) // 等于x的
38 {
39 int mid, reach = - 1 ;
40 while (low <= high)
41 {
42 mid = (low + high) / 2 ;
43 if (b[mid] == x)
44 return mid;
45 else if (b[mid] > x)
46 high = mid - 1 ;
47 else
48 low = mid + 1 ;
49 }
50 return reach;
51 }
52
53
54 int main()
55 {
56 int n, d;
57 while (scanf( " %d %d " , & n, & d) == 2 )
58 {
59 memset(c, 0 , sizeof (c));
60 for ( int i = 0 ; i < n; i ++ )
61 scanf( " %d " , & a[i]);
62 int cur = 0 ;
63 for ( int i = 0 ;i < n;i ++ )
64 {
65 idx[i * 3 ] = a[i] - d;
66 idx[i * 3 + 1 ] = a[i];
67 idx[i * 3 + 2 ] = a[i] + d;
68 }
69 sort(idx, idx + 3 * n);
70 b[cur ++ ] = idx[ 0 ];
71 for ( int i = 1 ;i < 3 * n;i ++ )
72 {
73 if (idx[i] != idx[i - 1 ])
74 b[cur ++ ] = idx[i];
75 }
76 int ans = 0 ;
77 for ( int i = 0 ; i < n; i ++ )
78 {
79 int now = binary_search( 0 , cur - 1 , a[i]) + 1 ;
80 assert(now != - 1 );
81 int pre = binary_search( 0 , cur - 1 , a[i] - d);
82 assert(pre != - 1 );
83 int nxt = binary_search( 0 , cur - 1 , a[i] + d) + 1 ;
84 assert(nxt != - 1 );
85 int cur = mod(sum(nxt) - sum(pre), MOD);
86 modify(now, cur + 1 );
87 ans = (ans + cur) % MOD;
88 }
89 printf( " %d\n " , ans);
90 }
91 return 0 ;
92 }

总结一下:近期的状态实在是不好,比赛的时候发挥的非常失常,先是斯坦福校赛的题一个最小路径覆盖没看出来,后是这次周赛的绝对悲剧收场……近期实在是太累了,考虑该休息一下恢复一下身体,也赶一下学业。数据库,计组,还有最当前的事计算方法的考试,Car sir的project赶紧完事吧,不能让这些东西拖我ACM的后腿了。

你可能感兴趣的:(第5次周赛)