比赛链接:http://www.51nod.com/contest/problemList.html#!contestId=21


1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostream> 19 #include <iomanip> 20 #include <cstring> 21 #include <climits> 22 #include <complex> 23 #include <fstream> 24 #include <cassert> 25 #include <cstdio> 26 #include <bitset> 27 #include <vector> 28 #include <deque> 29 #include <queue> 30 #include <stack> 31 #include <ctime> 32 #include <set> 33 #include <map> 34 #include <cmath> 35 36 using namespace std; 37 38 #define fr first 39 #define sc second 40 #define cl clear 41 #define BUG puts("here!!!") 42 #define W(a) while(a--) 43 #define pb(a) push_back(a) 44 #define Rint(a) scanf("%d", &a) 45 #define Rll(a) scanf("%lld", &a) 46 #define Rs(a) scanf("%s", a) 47 #define Cin(a) cin >> a 48 #define FRead() freopen("in", "r", stdin) 49 #define FWrite() freopen("out", "w", stdout) 50 #define Rep(i, len) for(int i = 0; i < (len); i++) 51 #define For(i, a, len) for(int i = (a); i < (len); i++) 52 #define Cls(a) memset((a), 0, sizeof(a)) 53 #define Clr(a, x) memset((a), (x), sizeof(a)) 54 #define Full(a) memset((a), 0x7f7f, sizeof(a)) 55 #define lrt rt << 1 56 #define rrt rt << 1 | 1 57 #define pi 3.14159265359 58 #define RT return 59 typedef long long LL; 60 typedef long double LD; 61 typedef unsigned long long ULL; 62 typedef pair<int, int> pii; 63 typedef pair<string, int> psi; 64 typedef map<string, int> msi; 65 typedef vector<LL> vl; 66 typedef vector<vl> vvl; 67 typedef vector<bool> vb; 68 69 LL p[11]; 70 int a,b,d,n; 71 72 int main() { 73 // FRead(); 74 int T; 75 Rint(T); 76 W(T) { 77 Cls(p); 78 Rint(a); Rint(b); Rint(d); Rint(n); 79 if(n==1) { 80 if(a*b >= 10) p[(a*b)/10]++; 81 p[(a*b)%10]++; 82 cout << p[d] << endl; 83 } 84 else { 85 int k = a*b; 86 int t = k / 10; 87 int x = k % 10; 88 int y = (x + t) / 10; 89 int g = (x +t) % 10; 90 int j = (x + y + t) % 10; 91 p[j] += n-2; 92 p[g] += 1; 93 p[x] += 1; 94 if(k >= 10) p[y+t] += 1; 95 cout << p[d] << endl; 96 } 97 } 98 RT 0; 99 }


1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostream> 19 #include <iomanip> 20 #include <cstring> 21 #include <climits> 22 #include <complex> 23 #include <fstream> 24 #include <cassert> 25 #include <cstdio> 26 #include <bitset> 27 #include <vector> 28 #include <deque> 29 #include <queue> 30 #include <stack> 31 #include <ctime> 32 #include <set> 33 #include <map> 34 #include <cmath> 35 36 using namespace std; 37 38 #define fr first 39 #define sc second 40 #define cl clear 41 #define BUG puts("here!!!") 42 #define W(a) while(a--) 43 #define pb(a) push_back(a) 44 #define Rint(a) scanf("%d", &a) 45 #define Rll(a) scanf("%lld", &a) 46 #define Rs(a) scanf("%s", a) 47 #define Cin(a) cin >> a 48 #define FRead() freopen("in", "r", stdin) 49 #define FWrite() freopen("out", "w", stdout) 50 #define Rep(i, len) for(int i = 0; i < (len); i++) 51 #define For(i, a, len) for(int i = (a); i < (len); i++) 52 #define Cls(a) memset((a), 0, sizeof(a)) 53 #define Clr(a, x) memset((a), (x), sizeof(a)) 54 #define Full(a) memset((a), 0x7f7f, sizeof(a)) 55 #define lrt rt << 1 56 #define rrt rt << 1 | 1 57 #define pi 3.14159265359 58 #define RT return 59 typedef long long LL; 60 typedef long double LD; 61 typedef unsigned long long ULL; 62 typedef pair<int, int> pii; 63 typedef pair<string, int> psi; 64 typedef map<string, int> msi; 65 typedef vector<LL> vl; 66 typedef vector<vl> vvl; 67 typedef vector<bool> vb; 68 69 70 const int maxn = 3333; 71 const int mod = 1000000007; 72 LL dp[maxn][maxn]; 73 LL ans; 74 int n; 75 76 int main() { 77 // FRead(); 78 while(~Rint(n)) { 79 Cls(dp); 80 dp[0][0] = dp[1][1] = 1; dp[2][2] = 2; 81 For(i, 3, n+1) { 82 Rep(j, i) { 83 For(k, 1, 17) { 84 dp[i][k] += (dp[j][k-1] * dp[i-j-1][k-1]) % mod; 85 if(dp[i][k] >= mod) dp[i][k] %= mod; 86 if(k >= 2) { 87 dp[i][k] += (dp[j][k-1] * dp[i-j-1][k-2]) % mod; 88 if(dp[i][k] >= mod) dp[i][k] %= mod; 89 } 90 dp[i][k] += (dp[j][k-2] * dp[i-j-1][k-1]) % mod; 91 if(dp[i][k] >= mod) dp[i][k] %= mod; 92 } 93 } 94 } 95 ans = 0; 96 Rep(i, 17) { 97 ans += dp[n][i]; 98 ans %= mod; 99 } 100 cout << ans << endl; 101 } 102 RT 0; 103 }


1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostream> 19 #include <iomanip> 20 #include <cstring> 21 #include <climits> 22 #include <complex> 23 #include <fstream> 24 #include <cassert> 25 #include <cstdio> 26 #include <bitset> 27 #include <vector> 28 #include <deque> 29 #include <queue> 30 #include <stack> 31 #include <ctime> 32 #include <set> 33 #include <map> 34 #include <cmath> 35 36 using namespace std; 37 38 #define fr first 39 #define sc second 40 #define cl clear 41 #define BUG puts("here!!!") 42 #define W(a) while(a--) 43 #define pb(a) push_back(a) 44 #define Rint(a) scanf("%d", &a) 45 #define Rll(a) scanf("%lld", &a) 46 #define Rs(a) scanf("%s", a) 47 #define Cin(a) cin >> a 48 #define FRead() freopen("in", "r", stdin) 49 #define FWrite() freopen("out", "w", stdout) 50 #define Rep(i, len) for(int i = 0; i < (len); i++) 51 #define For(i, a, len) for(int i = (a); i < (len); i++) 52 #define Cls(a) memset((a), 0, sizeof(a)) 53 #define Clr(a, x) memset((a), (x), sizeof(a)) 54 #define Full(a) memset((a), 0x7f7f, sizeof(a)) 55 #define lrt rt << 1 56 #define rrt rt << 1 | 1 57 #define pi 3.14159265359 58 #define RT return 59 typedef long long LL; 60 typedef long double LD; 61 typedef unsigned long long ULL; 62 typedef pair<int, int> pii; 63 typedef pair<string, int> psi; 64 typedef map<string, int> msi; 65 typedef vector<LL> vl; 66 typedef vector<vl> vvl; 67 typedef vector<bool> vb; 68 69 70 // const int maxn = ; 71 int n; 72 73 int main() { 74 // FRead(); 75 double r, R, s, v; 76 cin >> s; 77 78 r = sqrt(s / pi) / 2; 79 R = s / (pi * r) - r; 80 v = pi * r * r * sqrt(R * R - r * r) / 3; 81 printf("%.6lf\n", v);; 82 83 RT 0; 84 85 }


1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostream> 19 #include <iomanip> 20 #include <cstring> 21 #include <climits> 22 #include <complex> 23 #include <fstream> 24 #include <cassert> 25 #include <cstdio> 26 #include <bitset> 27 #include <vector> 28 #include <deque> 29 #include <queue> 30 #include <stack> 31 #include <ctime> 32 #include <set> 33 #include <map> 34 #include <cmath> 35 using namespace std; 36 #define fr first 37 #define sc second 38 #define cl clear 39 #define BUG puts("here!!!") 40 #define W(a) while(a--) 41 #define pb(a) push_back(a) 42 #define Rint(a) scanf("%d", &a) 43 #define Rll(a) scanf("%lld", &a) 44 #define Rs(a) scanf("%s", a) 45 #define Cin(a) cin >> a 46 #define FRead() freopen("in", "r", stdin) 47 #define FWrite() freopen("out", "w", stdout) 48 #define Rep(i, len) for(int i = 0; i < (len); i++) 49 #define For(i, a, len) for(int i = (a); i < (len); i++) 50 #define Cls(a) memset((a), 0, sizeof(a)) 51 #define Clr(a, x) memset((a), (x), sizeof(a)) 52 #define Full(a) memset((a), 0x7f7f, sizeof(a)) 53 #define lp p << 1 54 #define rp p << 1 | 1 55 #define pi 3.14159265359 56 #define RT return 57 #define lowbit(x) x & (-x) 58 #define onenum(x) __builtin_popcount(x) 59 typedef long long LL; 60 typedef long double LD; 61 typedef unsigned long long ULL; 62 typedef pair<int, int> pii; 63 typedef pair<string, int> psi; 64 typedef map<string, int> msi; 65 typedef vector<int> vi; 66 typedef vector<LL> vl; 67 typedef vector<vl> vvl; 68 typedef vector<bool> vb; 69 70 const int maxn = 300000; 71 int n; 72 LL k; 73 int bit[maxn<<1][2]; 74 int t[maxn], dp[maxn]; 75 76 void add(int i, int x, int j) { 77 while(i <= maxn) { 78 bit[i][j] += x; 79 i += lowbit(i); 80 } 81 } 82 83 int sum(int i, int j) { 84 int s = 0; 85 while(i) { 86 s += bit[i][j]; 87 i -= lowbit(i); 88 } 89 return s; 90 } 91 92 bool ok(int x) { 93 Cls(dp); Cls(bit); 94 Rep(i, n+1) { 95 if(t[i] >= x) dp[i] = dp[i-1] + 1; 96 else dp[i] = dp[i-1]; 97 } 98 Rep(i, n+1) dp[i] = 2 * dp[i] - i + 100000; 99 LL ret = 0; 100 Rep(i, n+1) { 101 ret += sum(dp[i]-1, !(i&1)); 102 add(dp[i], 1, i&1); 103 } 104 if(ret >= k) return 1; 105 return 0; 106 } 107 108 int main() { 109 // FRead(); 110 while(~Rint(n) && ~Rll(k)) { 111 int l = 0, r = 0; 112 For(i, 1, n+1) { 113 Rint(t[i]); 114 r = max(r, t[i]); 115 } 116 while(l <= r) { 117 int m = (l + r) >> 1; 118 if(ok(m)) l = m + 1; 119 else r = m - 1; 120 } 121 printf("%d\n", r); 122 } 123 RT 0; 124 }
E题:
二分中位数x,dp(i)维护[1,i]区间内大于等于x的数量。注意到长为奇数的区间[l,r],l和r奇偶一定不同,这一点非常重要。
如果区间[l,r]内的中位数大于等于x的话,那么(dp(r)-dp(l))*2>r-l+1,即2*dp[r]-r>2*dp(l)-l+1。
更新dp,使dp(i)-2*dp(i)-i,统计有多少个dp(j)<dp(i) j<i 且i,j奇偶不同。
有一个问题,就是2*dp[i]-i<0,解决方法就是加一个数,并且不至于让dp[i]计算后溢出的数。