终于来了一场个人赛, 结果惨不忍睹, 继续努力:
1.
http://codeforces.com/problemset/problem/501/B
没看懂题, 自己水平太渣了。
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main()
{
int n= 0,q=0;
map<string, string> vis;
cin >> q;
for(int i = 0;i < q; ++i)
{
string old, new_;
cin >> old >> new_;
if(vis.count(old))
{
string tmp = vis[old];
vis.erase(old);
vis[new_] = tmp;
}
else
{
vis[new_] = old;
}
}
cout << vis.size() << endl;
for(map<string, string> :: iterator it = vis.begin(); it != vis.end(); ++it)
{
cout << it->second << " " << it->first << endl;
}
return 0;
}
2.
http://codeforces.com/problemset/problem/538/B
当时没想懂, 脑子太慢, 借鉴之处, 数与字符串的转化, 思维的灵敏程度
<pre name="code" class="cpp">#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 1000;
vector<string> vis;
string str;
void solve()
{
bool ok = false;
string tmp;
while(1)
{
ok = false;
tmp.clear();
for(int i = 0; i < str.size(); ++i)
{
if(str[i] - '0' != 0)
{
ok = true;
tmp += '1';
str[i]--;
}
else if(str[i] - '0' == 0 && ok)
{
tmp +='0';
}
}
if(!ok) break;
else vis.push_back(tmp);
}
}
int main()
{
while(cin >> str)
{
vis.clear();
solve();
cout << vis.size() << endl;
for(int i = 0; i < vis.size(); ++i)
{
if(i==0) cout << vis[i];
else cout << " " << vis[i];
}
cout << "\n";
}
}
3.
http://codeforces.com/problemset/problem/467/C
上来就看得这个题, 又理解错了, 以为不能计算同一个数, 无奈了,
DP
dp[i][j] = max(dp[i-1][j], dp[i-m][j-1] + sum(i) - sum(i-m));
#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 5000 + 5;
long long int vis[maxn], sum[maxn], dp[maxn][maxn];
vector<long long int> p;
int main()
{
int n, m ,k;
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) cin >> vis[i];
for(int i = 1; i <= n; ++i) sum[i] = sum[i-1] + vis[i];
for(int i = m; i <= n ;++i)
{
if(i==m) p.push_back(sum[m]);
else p.push_back(sum[i] - sum[i-m]);
}
for(int i = m; i <= n; ++i)
{
for(int j = 1; j <= k; ++j)
{
<span style="white-space:pre"> </span> //printf("dp[%d][%d] = dp[%d][%d]: %lld dp[%d][%d]: %lld p[%d]: %lld\n", i, j
//,i-1, j , dp[i-1][j], i-m, j-1, dp[i-m][j-1],i-m, p[i-m]);
dp[i][j] = max(dp[i-1][j], dp[i-m][j-1] + p[i-m]);
}
}
cout << dp[n][k] << endl;
}