国庆5天乐在今天终于结束了,怀着明天又得上学的心情,我开始写这篇题解。
T1 wzoi
期望得分:100
实际得分:100
首先题面非常的迷,我看了十分钟都没懂,看完T2,T3后再回来看T1,总共看题看了20分钟才懂……
我发现最优的答案一定是回文串,那么ans = 10 * (len / 2),于是为了维护这个,我就开了个栈,如果栈是空的或者栈顶元素和当前数字不同,就放入栈,否则就把栈顶元素弹出,加10分。最后栈中要么不剩,要么一定是偶数个,加上5 * num / 2即可。
总的来说就是贪心,正确性其实我也不太确定,但是手出的数据都过了……
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 = 1e6 + 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 void MYFILE() 37 { 38 #ifndef mrclr 39 freopen("wzoi.in", "r", stdin); 40 freopen("wzoi.out", "w", stdout); 41 #endif 42 } 43 44 int n; 45 char c[maxn]; 46 int a[maxn]; 47 int st[maxn], sc = 0; 48 int ans = 0; 49 50 int main() 51 { 52 MYFILE(); 53 scanf("%s", c + 1); 54 n = strlen(c + 1); 55 for(int i = 1; i <= n; ++i) a[i] = c[i] - '0'; 56 for(int i = 1; i <= n; ++i) 57 { 58 if(!sc || st[sc] != a[i]) st[++sc] = a[i]; 59 else ans += 10, sc--; 60 } 61 if(sc) ans += 5 * (sc >> 1); 62 write(ans); enter; 63 return 0; 64 }