A题:
刚开始细菌有1只,然后每次分裂是x只细菌变成kx + b只细菌,n次分裂后得到z只细菌。问刚开始如果是t只细菌,至少需要多少次达到细菌个数不小于z只。
恶搞,刚开始1只细菌分裂n次每次是确定的,只需要判断t在哪个范围内即可。注意中间计算可能超long long!
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 ll;
int main() {
ll k, b, n, t;
scanf("%I64d%I64d%I64d%I64d", &k, &b, &n, &t);
ll ans = n, cur = 1;
while(cur < t && ans) {
cur = cur*k + b;
ans--;
}
if(cur > t) ans++;
printf("%I64d\n", ans);
return 0;
}
B题:
水题。。简单的bfs,居然写锉了= =
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 5;
struct PP {
int x, y, c;
PP(){}
PP(int x, int y, int c): x(x), y(y), c(c) {}
};
queue<PP> q;
int n, k;
char s[2][maxn];
bool vis[2][maxn];
bool bfs() {
q.push(PP(0, 0, 0));
vis[0][0] = true;
while(!q.empty()) {
PP cur = q.front(); q.pop();
int x = cur.x, y = cur.y, c = cur.c;
if(y + k >= n) return true;
if(s[x][y+1] != 'X' && !vis[x][y+1]) {
q.push(PP(x, y+1, c+1));
vis[x][y+1] = true;
}
if(y > 0 && s[x][y-1] != 'X' && !vis[x][y-1] && y-1 >= c+1) {
q.push(PP(x, y-1, c+1));
vis[x][y-1] = true;
}
if(s[x^1][y+k] != 'X' && !vis[x^1][y+k]) {
q.push(PP(x^1, y+k, c+1));
vis[x^1][y+k] = true;
}
}
return false;
}
int main() {
scanf("%d%d", &n, &k);
scanf("%s%s", s[0], s[1]);
if(bfs()) puts("YES");
else puts("NO");
return 0;
}
C题:
一个行星绕着太阳转,行星速度大小固定,有一个飞船要到行星上去,飞船速度大小固定,方向随你,问飞船最快要多久到达行星上。
思路:二分时间!确定时间后的飞船位置是确定的,然后计算行星到那个地方的最短时间!