今天很不厚道的咕咕了,再次忏悔
明天一定好好做题(
DAY1
A一个三分的题
题意:给n个点,在x轴上寻找一个答案点,使得所有点到这个答案点距离的最大值最小。
那么答案一定是在最大坐标与最小坐标之间的,三分(二分貌似会t)寻找答案。
队友机智 打call
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 50005;
const long double inf = 0x3f3f3f3f,er=1e-10;
struct P {
long double x, y;
}p[maxn];
int n;
long double dis(long double xx) {
long double tmp = 0;
for (int i = 1;i <= n;i++) {
tmp = max(tmp, (p[i].x - xx)*(p[i].x - xx) + p[i].y*p[i].y);
}
return tmp;
}
int main()
{
while (scanf_s("%d", &n)&&n) {
long double l = inf, r = -inf;
for (int i = 1;i <= n;i++) {
scanf_s("%lf %lf", &p[i].x, &p[i].y);
l = min(l, p[i].x);
r = max(r, p[i].x);
}
while (abs(r - l) > er && r>l) {
//cout << l << " " << r << endl;
long double midl = (l + r) / 2.0, midr = (midl+r) / 2.0;
if (dis(midl) > dis(midr)) l = midl;
else r=midr;
}
cout <<fixed << setprecision(9)<<l<< " " << sqrt(dis(l)) << endl;
}
return 0;
}
B 放盘子 Working at the Restaurant
两堆盘子,三种操作(DROP放,TAKE取,MOVE盘子在两堆间转移)
终于AC了
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "pch.h"
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int n, m;
int p1, p2;
int main(){
while (scanf_s("%d", &n)&&n) {
p1 = 0;p2 = 0;
for (int i = 1;i <= n;i++) {
string s;
cin >> s >> m;
if (s == "DROP") {
p2 += m;
printf("DROP 2 %d\n", m);
}
else {
if (p1 >= m) {
printf("TAKE 1 %d\n", m);
p1 -= m;
m = 0;
}
else {
if (p1) {
printf("TAKE 1 %d\n", p1);
m -= p1;
p1 = 0;
}
if (m) {
printf("MOVE 2->1 %d\n", p2);
p1 += p2;
p2 = 0;
printf("TAKE 1 %d\n", m);
p1 -= m;
}
}
}
}
}
return 0;
}
I 打电话(? 有点不懂这个题h
开始以为是线段树,看准范围试了一下,确实有点水,还可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 10005;
int ed[N], sta[N];
int main()
{
int n, m;
while (scanf_s("%d%d", &n, &m) && n != 0 && m != 0)
{
memset(ed, 0, sizeof(ed));
memset(sta, 0, sizeof(sta));
for (int i = 1;i <= n;i++)
{
int s, d, duration;
scanf_s("%d%d%d%d", &s, &d, &sta[i], &duration);
ed[i] = sta[i] + duration;
}
int askx, asky;
for (int i = 1;i <= m;i++)
{
int ans = 0;
scanf_s("%d%d", &askx, &asky);
for (int i = 1;i <= n;i++) {
if (sta[i]>=asky+askx || ed[i]<=askx);
else ans++;
}
printf("%d\n", ans);
}
}
return 0;
}
F.Haunted Graveyard
一顿暴力发现是图论
tle果然。
这个是tle代码哈 而且题意也理解错了,原来是上下左右。
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include<map>
using namespace std;
int w, h, g,e;
int time;
const int inf = 0x3f3f3f3f;
bool f = 0;
int book[50][50], cir = 0;
int mp[50][50];
struct P {
int ex, ey;
int t;
};
map <pair<int, int>, P> a;
void ini() {
for (int i = 0;i < 50;i++) {
for (int j = 0;j < 50;j++) {
mp[i][j] = 1;
book[i][j] = 0;
}
}
time = inf;
f = 0;cir = 0;
}
void dfs(int x, int y, int lx,int ly,int t) {
if (x==lx && y ==ly || cir) {
cir = 1;
return;
}
if (x == w - 1 && y == h - 1) {
time = min(time, t);
return;
}
int nx, ny;
nx = x + 1;ny = y;
if (nx<0 || nx>w-1 || ny<0 || ny>h-1 || book[nx][ny]);
else {
if (mp[nx][ny] == 1) {
book[nx][ny] ++;
dfs(nx, ny, x,y,t + 1);
book[nx][ny] --;
}
else if (mp[nx][ny] == 2)
{
//cout << "H!" << nx << " " << ny << endl;
P np = a[pair<int, int>(nx, ny)];
book[nx][ny] ++;
dfs(np.ex, np.ey, x,y,t + np.t + 1);
book[nx][ny] --;
}
else;
}
nx = x;ny = y + 1;
if (nx<0 || nx>w-1 || ny<0 || ny>h-1 || book[nx][ny]);
else {
if (mp[nx][ny] == 1 && !book[nx][ny]) {
book[nx][ny] ++;
dfs(nx, ny, x,y,t + 1);
book[nx][ny] --;
}
else if (mp[nx][ny] == 2 )
{
//cout << "H!" << nx << " " << ny << endl;
P np = a[pair<int, int>(nx, ny)];
book[nx][ny] ++;
dfs(np.ex, np.ey,x,y, t + np.t+1);
book[nx][ny] --;
}
else;
}
nx = x - 1;ny = y - 1;
if (nx<0 || nx>w-1 || ny<0 || ny>h-1 || book[nx][ny]);
else {
if (mp[nx][ny] == 1) {
book[nx][ny] ++;
dfs(nx, ny, t + 1,x,y);
book[nx][ny] --;
}
else if (mp[nx][ny] == 2 )
{
//cout << "H!" << nx << " " << ny << endl;
P np = a[pair<int, int>(nx, ny)];
book[nx][ny] ++;
dfs(np.ex, np.ey, x,y,t + np.t +1);
book[nx][ny] --;
}
else;
}
return;
}
int main() {
while(cin >> w >> h && w && h){
ini();
cin >> g;
for (int i = 1;i <= g;i++) {
int x, y;
cin >> x >> y;
mp[x][y] = 0;
}
cin >> e;
for (int i = 1;i <= e;i++) {
int x1, y1, x2, y2, t;
cin >> x1 >> y1 >> x2 >> y2 >> t;
mp[x1][y1] = 2;
P p;
p.ex = x2;p.ey = y2;p.t = t;
a.insert(make_pair(pair<int,int>(x1, y1), p));
}
dfs(0, 0, -1,-1,0);
if (cir) cout << "Never" << endl;
else {
if (time == inf) {
cout << "Impossible" << endl;
}
else {
cout << time<< endl;
}
}
}
return 0;
}
对着网上的AC代码debug了2h,终于找出bug了
真实落泪(终点不可加入图 ,是为什么呢?好像还是没懂)
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 1005, inf = 0x3f3f3f3f;
int mp[50][50], dis[maxn], cnt[maxn];
int w, h, e, g;
bool vis[maxn];
struct Edge {
int to, val;
Edge(int _to=0,int _val=0):to(_to),val(_val){}
};
set<int> grave, bh;
vector<Edge> G[maxn];
int nxt[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
void addedge(int u, int v,int w) {
G[u].push_back(Edge(v, w));
}
int cal(int x, int y) {
//要为他们找到合适的编号方式
return (x - 1) * h + y;
}
bool work(int s, int e) {
memset(vis, false, sizeof(vis));
for (int i = 0;i <= e;i++) {
dis[i] = inf;
}
vis[s] = true;
dis[s] = 0;
queue<int> q;
while (!q.empty()) q.pop();
q.push(s);
memset(cnt, 0, sizeof(cnt));
cnt[s] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
vis[u] = false;
for (int i = 0;i < G[u].size();i++) {
int v = G[u][i].to;
int w = G[u][i].val;
if (dis[v] > dis[u] + w) {
dis[v] = dis[u] + w;
if (!vis[v]) {
vis[v] = true;
q.push(v);
if (++cnt[v] >e)
return 1;
}
}
}
}
return 0;
}
int main() {
while (cin >> w >> h && w!=0 && h!=0) {
for (int i = 1;i <= w;i++) {
for (int j = 1;j <= h;j++) {
mp[i][j] = 0;
}
}
grave.clear();bh.clear();
for (int i = 0;i <= cal(w, h);i++) {
G[i].clear();
}
cin >> g;
for (int i = 1;i <= g;i++) {
int x, y;
cin >> x >> y;
x++;y++;
grave.insert(cal(x, y));
mp[x][y] = -1;
}
cin >> e;
for (int i = 1;i <= e;i++) {
int x1, y1, x2, y2, t;
cin >> x1 >> y1 >> x2 >> y2 >> t;
x1++;y1++;x2++;y2++;
addedge(cal(x1, y1), cal(x2, y2), t);
mp[x1][y1] = 1;
bh.insert(cal(x1, y1));
}
for (int i = 1;i <= w;i++) {
for (int j = 1;j <= h;j++) {
int now = cal(i, j);
//试过了 这不可少 wa了无数次 哭哭
if (i == w && j == h) continue;
if(mp[i][j]==0) {
for (int k = 0;k < 4;k++) {
int nx = i + nxt[k][0];
int ny = j + nxt[k][1];
if (nx<1 || nx>w || ny<1 || ny>h)
continue;
int to = cal(nx, ny);
if (mp[nx][ny]==-1) {
continue;
}
else {
addedge(now, to, 1);
}
}
}
}
}
bool cir;
cir=work(cal(1, 1), cal(w, h));
if (cir) {
cout << "Never" << endl;
}
else {
if (dis[cal(w, h)] >= inf)
cout << "Impossible" << endl;
else
cout << dis[cal(w, h)] << endl;
}
}
return 0;
}
DAY2
好像是江西省赛
A.树的重心
贴个别人的AC代码
#include "pch.h"
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
const int N = 100005;
long long n, root, sz[N], sum[N], tmpsum;
long long ans;
vector<int>G[N];
bool vis[N];
void dfsOne(int u, int fa) {
sz[u] = 1;
vis[u] = true;
for (int v : G[u]) {
if (v == fa) {
continue;
}
dfsOne(v, u);
sz[u] += sz[v];
sum[u] += sum[v] + sz[v];
}
}
void dfsTwo(int u, int fa) {
if (tmpsum > sum[u]) {
root = u;
tmpsum=sum[u];
}
for (int v : G[u]) {
if (v == fa) {
continue;
}
long long tmp = sum[u] - sum[v] - sz[v];
sum[v] += tmp + sz[u] - sz[v];
sz[v] += sz[u] - sz[v];
dfsTwo(v, u);
}
}
void dfs(int u, int fa) {
sz[u] = 1;
for (int v : G[u]) {
if (v == fa) continue;
dfs(v, u);
sz[u] += sz[v];
ans += (n - sz[v])*sz[v];
}
}
int main(){
cin >> n;
for (int i = 1;i <= n - 2;i++) {
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
int rt1 = 1, rt2 = 1;
root = 1;
dfsOne(1, 0);
tmpsum = sum[1];
dfsTwo(1, 0);
rt1 = root;
while (vis[rt2]) {
rt2++;
}
root = rt2;
dfsOne(rt2, 0);
tmpsum = sum[rt2];
dfsTwo(rt2, 0);
rt2 = root;
G[rt2].push_back(rt1);
G[rt1].push_back(rt2);
ans = 0;
dfs(1, 0);
cout << ans << endl;
return 0;
}
D.Wave
疯狂暴力
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int n, c,tmp;
int v[105][100005];
int num[100005];
int cnt[105];
int check(int x, int y) {
int t = 1;bool f = 0;
if (v[x][1] < v[y][1]) {
for (int i = 1;i <= n;i++) {
if (f == 1 && num[i] == x) {
f = 0;
t++;
}
if (f == 0 && num[i] == y) {
f = 1;
t++;
}
}
}
else {
for (int i = 1;i <= n;i++) {
if (f == 0 && num[i] == x) {
f = 1;
t++;
}
if (f == 1 && num[i] == y) {
f = 0;
t++;
}
}
}
return t;
}
int main(){
cin >> n >> c;
for (int i = 1;i <= n;i++) {
cin >> num[i];
cnt[num[i]]++;
//这个数第cnt次出现的位置
v[num[i]][cnt[num[i]]] = i;
}
for (int i = 1;i <= c;i++) {
for (int j = i+1;j <= c;j++) {
if(cnt[i]&&cnt[j])
tmp = max(tmp, check(i, j));
}
}
cout << tmp << endl;
return 0;
}
F.String
还行,签到
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int N;
int gcd(int x, int y) {
return y == 0 ? x : gcd(y, x%y);
}
int main()
{
while (cin >> N) {
int a=0, v=0, i=0, n=0;
string s;
cin >> s;
for (int j = 0;j < N;j++) {
if (s[j] == 'a') a++;
if (s[j] == 'v') v++;
if (s[j] == 'i') i++;
if (s[j] == 'n') n++;
}
if (a*v*i*n == 0) {
cout << "0/1" << endl;
}
else {
int fenzi = a*v*i*n;
int fenmu = N*N*N*N;
cout << fenzi / gcd(fenzi, fenmu) << "/" << fenmu / gcd(fenzi, fenmu) << endl;
}
}
return 0;
}
G.Traffic
这也是暴力 枚举 害。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int n, m;
int b[5005];
int flag[5005];
int mark[5005];
bool check(int x)
{
for (int i = 1;i < 5005;i++)
mark[i] = 0;
for (int i = 1;i <= m;i++)
{
if (flag[b[i] + x] == 0 && mark[b[i] + x] == 0)
{
mark[b[i] + x] = 1;
}
else return 0;
}
return 1;
}
int main()
{
while (cin>>n>>m)
{
for (int i = 0;i < 5005;i++)
flag[i] = 0;
for (int i = 1;i <= n;i++)
{int x; cin>>x; flag[x]=1;}
for (int i = 1;i <= m;i++)
cin>>b[i];
sort(b + 1, b + 1 + m);
for (int i = 0;i <= m + n;i++)
{
if (check(i))
{
cout<<i<<endl;
break;
}
}
}
return 0;
}
H.Rng
分数取模运算 -
a^(p-1) mod p = 1 mod p
a^(p-2) mod p = a^(-1) mod p
即(a/b)mod p = a * b^(-1) mod p = a* b^(p-2) mod p
找规律+快速幂的题
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
const int mod = 1e9 + 7;
int n;
long long ksm(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) {
res =(res* a)%mod;
}
a = a * a%mod;
b >>= 1;
}
return res;
}
int main(){
while (cin >> n) {
cout << (n+1) * ksm(n*2, mod-2) % mod << endl;
}
return 0;
}
I WA了几次tcl
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int n;
int main()
{
while (cin >> n) {
double ans = 0;
for (int i = 1;i <= n;i++) {
string s;
cin >> s;
int mark = 0;
for (int j = 0;j < s.length();j++) {
if (s[j] == '.') {
mark = j;
break;
}
}
ans += s[mark + 3] >= '5' ? 0.001*(10 - (s[mark + 3] - '0')) : -0.001*(s[mark + 3] - '0');
}
cout << fixed << setprecision(3) << ans << endl;
}
return 0;
}
J 题面差评 疯狂忘记longlong
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
long long n, m,w[1006];
long long p,c;
long long gcd(long long x, long long y) {
return y == 0 ? x : gcd(y,x%y);
}
int main()
{
while (cin >> n >> m) {
p=1;c=0;
for (int i = 1;i <= n;i++) {
cin >> w[i];
p = w[i] *p / gcd(p, w[i]);
}
for (int i = 1;i <= n;i++) {
c += p / w[i];
}
if (m%c || m < c) cout << "No" << endl;
else {
cout << "Yes" << endl;
long long k = m / c;
for (int i = 1;i < n;i++) {
cout << p*k / w[i] << " ";
}
cout << k*p / w[n] << endl;
}
}
return 0;
}
K 签到快乐
#include<iostream>
using namespace std;
int x, y;
int main()
{
cin >> x >> y;
cout << (x*x - y*y) / 4 << endl;
return 0;
}
DAY3
A水题暴力
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
int N, k,ans;
bool light[1000005];
void work(int x) {
int t = 0;
for (int i = 1;i <= N;i++) {
if (i%x == 0) {
light[i] = light[i] == 0 ? 1 : 0;
}
t += int(light[i] == 1);
}
ans = max(ans, t);
}
int main() {
cin >> N >> k;
for (int i = 1;i <= k;i++) {
int x;
cin >> x;
work(x);
}
cout << ans << endl;
return 0;
}
G.Rounding
听了下题解 感觉差不多,好像没有特别强调细节,明天如果还有空再试试
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "pch.h"
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
int p;
string ss[10005];
int book[10005];
const int inf = 999;
int r = -1, l = -1, sum = 0;
int z, h;
bool check() {
if (p == 1) {
r = 0;l = 0;
return book[1] == 10000;
}
if (h > 2) return 0;
//目前结果与100的差值
int cha = 10000 - sum;
//可用来均摊增量的个数
int big = p - h;
//增量
int less = p - z;
bool f = 0;
for (int i = 49;i >= -50;i--) {
//枚举上界增量 如果增量过多 需要分摊减小
int s = cha - i;
if (s < 0) {
int share = -inf;
if (less + z - 1 > 0)
share = floor(s / (1.0*(less + z - 1)));
//buxing 摊不了
if (share < -50) continue;
}
//如果增量能够
f = 1;
r = i;
break;
}
if (!f) return 0;
f = 0;
for (int i = -50;i <= 49;i++) {
int s = cha - i;
if (s) {
int share = inf;
if (big + h - 1 > 0)
share = ceil(s / (1.0*(big + h - 1)));
//GG
if (share > r) continue;
}
f = 1;
l = i;
break;
}
return f && l <= r;
}
int main()
{
cin >> p;
for (int i = 1;i <= p;i++) {
cin >> ss[i] >> book[i];
if (book[i] == 0) z++;
if (book[i] == 100) h++;
book[i] *= 100;
sum += book[i];
}
if (check()) {
for (int i = 1;i <= p;i++) {
cout << fixed << setprecision(2) << ss[i] << " " << max(0.00, (book[i] + l) / 100.0) << " " << min(100.00, (book[i] + r) / 100.0) << endl;
}
}
else cout << "IMPOSSIBLE" << endl;
return 0;
}
想补H
DAY 4
A.嫖来的
#include "pch.h"
#include<iostream>
#include<queue>
#include<unordered_set>
using namespace std;
struct board {
int arr[6][6];
board() {
memset(arr, 0, sizeof(arr));
}
};
struct state {
int x[11], y[11];
bool operator ==(const state & b)const {
for (int i = 1;i <= 10;i++)
if (x[i] != b.x[i] || y[i] != b.y[i])
return false;
return true;
}
};
struct Hash {
size_t operator() (state State) const {
size_t res = 0;
for (int i = 1;i <= 10;i++) {
res = res * 7 + size_t(State.x[i]);
res = res * 7 + size_t(State.y[i]);
}
return res;
}
};
int dir[11], len[11];
board st;
state st_state;
queue< pair<int, state> > que;
unordered_set<state, Hash> Set;
board generateBoard(state State) {
board t;
for (int i = 1;i <= 10;i++) {
//如果此处有车
if (dir[i] > 0) {
int dx = 0, dy = 0;
int x = State.x[i];
int y = State.y[i];
//水平方向
if (dir[i] == 1) dy = 1;
//垂直方向
else dx = 1;
for (int j = 0;j < len[i];j++) {
t.arr[x][y] = i;
x += dx;y += dy;
}
}
}
return t;
}
int bfs() {
que.push(pair<int, state>(0, st_state));
Set.insert(st_state);
while (!que.empty()) {
auto tmp = que.front();
int nows = tmp.first;
state nowstate = tmp.second;
que.pop();
if (nows == 10)continue;
board nowboard = generateBoard(nowstate);
for (int i = 1;i <= 10;i++) {
if (dir[i] == 0) continue;
state tmpstate = nowstate;
int dx = 0, dy = 0;
if (dir[i] == 1) dy = 1;
else dx = 1;
//?
if (nowstate.x[i] + dx * len[i] < 6 &&
nowstate.y[i] + dy * len[i] < 6 &&
nowboard.arr[nowstate.x[i] + dx * len[i]][nowstate.y[i] + dy * len[i]] == 0) {
tmpstate.x[i] = nowstate.x[i] + dx;
tmpstate.y[i] = nowstate.y[i] + dy;
if (Set.find(tmpstate) == Set.end()) {
if (tmpstate.y[1] + len[1] - 1 == 5) {
if (nows + 1 + len[1] <= 10)
return nows + 1 + len[1];
return -1;
}
que.push(pair<int, state>(nows + 1, tmpstate));
Set.insert(tmpstate);
}
}
if (nowstate.x[i] - dx >= 0 &&
nowstate.y[i] - dy >= 0 &&
nowboard.arr[nowstate.x[i] - dx][nowstate.y[i] - dy] == 0) {
tmpstate.x[i] = nowstate.x[i] - dx;
tmpstate.y[i] = nowstate.y[i] - dy;
if (Set.find(tmpstate) == Set.end()) {
if (tmpstate.y[1] + len[1] - 1 == 5) {
if (nows + 1 + len[1] <= 10)
return nows + 1 + len[1];
return -1;
}
que.push(pair<int, state>(nows + 1, tmpstate));
Set.insert(tmpstate);
}
}
}
}
return -1;
}
int main() {
for (int i = 0;i < 6;i++)
for (int j = 0;j < 6;j++)
cin >> st.arr[i][j];
for (int i = 0;i < 6;i++)
for (int j = 0;j < 6;j++)
if (st.arr[i][j]>0) {
int t = st.arr[i][j];
if (dir[t] > 0) continue;
st_state.x[t] = i;
st_state.y[t] = j;
int dx = 0, dy = 0;
if (j + 1 < 6 && st.arr[i][j + 1] == t) {
dir[t] = 1;
dy = 1;
}
else {
dir[t] = 2;
dx = 1;
}
int x = i, y = j;
len[t] = 0;
while (st.arr[x][y] == t) {
len[t]++;
x += dx;y += dy;
}
}
if (st_state.x[1] != 2 || dir[1] != 1) {
cout << -1 << endl;
return 0;
}
cout << bfs() << endl;
return 0;
}
. Are they all Integers? 签到
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 100;
int num[maxn];
int n;
int main() {
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> num[i];
}
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= n;j++) {
if (i != j) {
for (int k = 1;k <= n;k++) {
if (k != j && k != i) {
if ((num[i] - num[j]) % num[k]) {
cout << "no" << endl;
return 0;
}
}
}
}
}
}
cout << "yes" << endl;
return 0;
}
D. 珍珠奶茶欸 签到
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
char t1[50] = "bubble";
char t2[50] = "tapioka";
int main() {
char x[40];
bool f = 0;
while (cin >> x) {
if (strcmp(t1, x) == 0 || strcmp(t2, x) == 0);
else {
f = 1;
cout << x << " ";
}
}
if (!f) cout << "nothing" << endl;
return 0;
}
E. The League of Sequence Designers 构造题
队友nb!注意数据范围 自己写还wa了三次 tcl
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
int t, k, l;
int main() {
cin >> t;
while (t--) {
cin >> k >> l;
if (l > 1999) {
cout << -1 << endl;
}
else {
cout << 1999 << endl;
int s = 1999 + k;
int cnt = 0;
cout << -1 << " ";
for (int i = 2;i <= 1999;i++) {
if (cnt < s % 1998) {
cnt++;
cout << s / 1998 + 1 << " ";
}
else cout << s / 1998 << " ";
}
cout << endl;
}
}
return 0;
}
H.把1/n拆成1/n(n+1)+1/(n+1)
J.bitset枚举
#include<iostream>
#include<queue>
#include<bitset>
using namespace std;
bitset<500> num[30];
int main() {
int t,m,n,ans;
cin >> t;
while (t--) {
cin >> n >> m;
for (int i = 1;i <= m;i++) {
string s;
cin >> s;
num[i] = bitset<500>(s);
}
int len = 1 << m;
ans = m + 1;
for (int i = 1;i < len;i++) {
int t = i;
int s = 0;
bitset<500> now(0);
for (int j = 1;j <= m && t > 0;j++) {
if (t & 1) {
now = now | num[j];
s++;
}
t /= 2;
}
if (now.count() == n) {
ans = min(ans, s);
}
}
if (ans == m + 1) cout << -1 << endl;
else cout << ans << endl;
}
return 0;
}
K. 石子合并类似 模拟一下就好re