T1
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("graph.in","r",stdin);
freopen("graph.out","w",stdout);
int W, H, a;
cin >> W >> H >> a;
int ans = ceil(W * 1.0 / a) * ceil(H * 1.0 / a);
cout << ans;
return 0;
}
T2
#include<bits/stdc++.h>
using namespace std;
int cnt[10];
int main()
{
freopen("plate.in","r",stdin);
freopen("plate.out","w",stdout);
int f, n;
cin >> f >> n;
cnt[f] = n; //楼层号需要n个
for(int i = 1; i <= n; i++)
{
if(i < 10)//处理房间号是01、02、...、09的情况
{
cnt[0]++;
}
int tmp = i;
while(tmp)
{
cnt[tmp % 10]++;
tmp /= 10;
}
}
for(int i = 0; i < 10; i++)
{
cout << cnt[i] << ' ';
}
return 0;
}
T3
#include<iostream>
using namespace std;
int main()
{
freopen("left.in","r",stdin);
freopen("left.out","w",stdout);
int n, dir = 0;
cin >> n;
for(int i = 0; i < n; i++)
{
string cmd;
cin >> cmd;
if("left" == cmd)
{
dir += 3;
}
else if("right" == cmd)
{
dir += 1;
}
else
{
dir += 2;
}
}
char res[4] = {'N', 'E', 'S', 'W'};
cout << res[dir % 4];
return 0;
}
T4
#include<iostream>
using namespace std;
int main()
{
freopen("race.in", "r", stdin);
freopen("race.out", "w", stdout);
int a, b, t;
cin >> a >> b >> t;
int dist1 = 0, dist2 = 0; //兔子行程和乌龟行程
while(dist1 < t && dist2 < t)
{
if(dist1 <= dist2) //兔和龟同一位置,或兔在后
{
dist1 += a;
}
dist2 += b;
}
if(dist1 < t)
{
cout << "wugui";
}
else if(dist2 < t)
{
cout << "tuzi";
}
else
{
dist1 -= a;
dist2 -= b;
if((t - dist1) * 1.0 / a < (t - dist2) * 1.0 / b)
{
cout << "tuzi";
}
else if((t - dist1) * 1.0 / a > (t - dist2) * 1.0 / b)
{
cout << "wugui";
}
else
{
cout << "tongshi";
}
}
return 0;
}
T5
解法一:70分
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 5;
int dp[maxN];
int main()
{
freopen("trans.in", "r", stdin);
freopen("trans.out", "w", stdout);
string s;
cin >> s;
int len = s.size();
for(int now = 0; now < len; now++)
{
dp[now] = 1;
for(int pre = 0; pre < now; pre++)
{
if(s[pre] <= s[now])
{
dp[now] = max(dp[now], dp[pre] + 1);
}
}
}
cout << len - *max_element(dp, dp + len);
return 0;
}
解法二:100分
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 5;
int dp[maxN];
char a[maxN], b[maxN];
int main()
{
freopen("trans.in", "r", stdin);
freopen("trans.out", "w", stdout);
cin >> a;
int len = strlen(a);
b[0] = a[0];
int pos = 0;
for(int i = 1; i < len; i++)
{
if(a[i] >= b[pos])
{
b[++pos] = a[i];
}
else
{
int tmp = (upper_bound(b, b + pos + 1, a[i])) - b;
b[tmp] = a[i];
}
}
cout << len - (pos + 1);
return 0;
}
==============================
长按识别二维码加好友咨询信奥课或进信息学竞赛群