这一套模拟卷我觉得难度不是很高,挺良心的,会的分也都拿到了,不会的就是不会……
题面就不放上来啦~~gg不让~~
T1 flower
最大值最小?那果断二分啊。
二分一个最小高度,然后judge的时候从头开始扫就行,遇到一个高度比mid小的就从这个数开始把长度为L的区间加上这个差值,并记录天数,如果超过m天就返回false。区间修改第一反应是线段树,但其实差分就行了,还是O(1)的。总复杂度O(nlogn)。
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdlib> 7 #include<cctype> 8 #include<vector> 9 #include<stack> 10 #include<queue> 11 using namespace std; 12 #define enter puts("") 13 #define space putchar(' ') 14 #define Mem(a, x) memset(a, x, sizeof(a)) 15 #define rg register 16 typedef long long ll; 17 typedef double db; 18 const int INF = 0x3f3f3f3f; 19 const db eps = 1e-8; 20 const int maxn = 1e5 + 5; 21 inline ll read() 22 { 23 ll ans = 0; 24 char ch = getchar(), last = ' '; 25 while(!isdigit(ch)) {last = ch; ch = getchar();} 26 while(isdigit(ch)) {ans = ans * 10 + ch - '0'; ch = getchar();} 27 if(last == '-') ans = -ans; 28 return ans; 29 } 30 inline void write(ll x) 31 { 32 if(x < 0) x = -x, putchar('-'); 33 if(x >= 10) write(x / 10); 34 putchar(x % 10 + '0'); 35 } 36 37 int n, m, L, a[maxn], dif[maxn]; 38 39 bool judge(ll x) 40 { 41 for(int i = 1; i <= n; ++i) dif[i] = a[i] - a[i - 1]; 42 ll now = 0; ll cnt = 0; 43 for(int i = 1; i <= n; ++i) 44 { 45 now += dif[i]; 46 if(now < x) 47 { 48 cnt += x - now; 49 if(cnt > m) return 0; 50 dif[i] += x - now; 51 if(i + L <= n) dif[i + L] -= x - now; 52 now = x; 53 } 54 } 55 return 1; 56 } 57 58 int main() 59 { 60 freopen("flower.in", "r", stdin); 61 freopen("flower.out", "w", stdout); 62 n = read(); m = read(); L = read(); 63 for(int i = 1; i <= n; ++i) a[i] = read(); 64 ll L = 0, R = (ll)1e10; 65 while(L < R) 66 { 67 ll mid = (L + R + 1) >> 1; 68 if(judge(mid)) L = mid; 69 else R = mid - 1; 70 } 71 write(L); enter; 72 return 0; 73 }
T2 treasure
正解自然是想不出来,在OI生涯中好像没遇到能有数据结构优化矩阵旋转的……于是开始杠30分。
昨天刚好在初赛书上看到了一个O(n2)旋转矩阵的,于是就用上了,O(n3)暴力,30分应该是稳了。
正解自认为是一个很偏的知识点:链表。反正我好想总共就写过两次。说是暴力链表维护某一个东西,剩下就不太懂了。而且标程的代码也挺长,看不太懂。
T3 red
就喜欢这么短的题面,省去了我那么多读题的时间(我语文菜啊)。
然而看到幻想乡还是不由得惊了一下,因为今天刚把红色的幻想乡给AC了……
一眼就知道是期望dp,然后看了看数据范围,很明显是一个二维状态O(n2)的复杂度。于是设dp[i][j]表示有 i 张红牌,j 张黑牌的时候的最优的幻想乡币期望。
于是dp[i][j]分别从dp[i - j][j]和dp[i][j - 1]转移过来,分别代表这一次翻了红牌/黑牌的情况,于是有:
dp[i][j] = max( (dp[i - 1][j] + 1) * i / (i + j) + (dp[i][j - 1] - 1) * i / (i + j), 0)
然后忘了初始化dp[i][0] = i,调了半天。
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdlib> 7 #include<cctype> 8 #include<vector> 9 #include<stack> 10 #include<queue> 11 using namespace std; 12 #define enter puts("") 13 #define space putchar(' ') 14 #define Mem(a, x) memset(a, x, sizeof(a)) 15 #define rg register 16 typedef long long ll; 17 typedef double db; 18 const int INF = 0x3f3f3f3f; 19 const db eps = 1e-8; 20 const int maxn = 1e3 + 5; 21 inline ll read() 22 { 23 ll ans = 0; 24 char ch = getchar(), last = ' '; 25 while(!isdigit(ch)) {last = ch; ch = getchar();} 26 while(isdigit(ch)) {ans = ans * 10 + ch - '0'; ch = getchar();} 27 if(last == '-') ans = -ans; 28 return ans; 29 } 30 inline void write(ll x) 31 { 32 if(x < 0) x = -x, putchar('-'); 33 if(x >= 10) write(x / 10); 34 putchar(x % 10 + '0'); 35 } 36 37 int n, m; 38 db dp[maxn][maxn]; 39 40 db Max(db a, db b) 41 { 42 return a > b ? a : b; 43 } 44 45 int main() 46 { 47 freopen("red.in", "r", stdin); 48 freopen("red.out", "w", stdout); 49 n = read(); m = read(); 50 for(int i = 1; i <= n; ++i) 51 { 52 dp[i][0] = i; 53 for(int j = 1; j <= m; ++j) 54 dp[i][j] = Max(0.0,(dp[i - 1][j] + 1) * (db)i / (db)(i + j) + (dp[i][j - 1] - 1) * (db)j / (db)(i + j)); 55 } 56 printf("%.8lf ", dp[n][m]); 57 return 0; 58 }
嗯……完啦。