T1
很明显的暴力,首先可以看到就是一个二进制加法,在二进制下的某一位上 加一,直接模拟即可
期望得分 \(100\)
代码如下
/*
/> フ
| _ _|
/`ミ _x 彡
/ |
/ ヽ ?
/ ̄| | | |
| ( ̄ヽ__ヽ_)_)
\二つ
*/
#include<bits/stdc++.h>
using namespace std;
long long read()
{
long long x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
return x * f;
}
char s[1000100];
int a[1000100], ans, n, m;
int main()
{
n = read();
scanf("%s", s);
for(int i = 0; i < n; i++)
{
if(s[n - i - 1] == '0') a[i] = 0;
else a[i] = 1;
}
n += 30;
m = read();
while(m--)
{
int x = read();
ans = 0;
++a[x];
ans++;
while(a[x] >= 2) ++a[x + 1], a[x] -= 2, ++x, ++ans;
cout << ans << '\n';
}
for(int i = n - 1; i >= 0; i--)
{
if(a[i] != 0)
{
for(int j = i; j >= 0; j--)
{
cout << a[j];
}
break;
}
}
return 0;
}
T2
一道找规律题,玩玩小样例看不出来,但是大样例的规律挺明显的,如果有负数,那就取连续的负数中最小的一个(其实取哪一个都一样,但是std是这么构造的),对于正数,直接取,不需要删去.
期望分数100
/*
/> フ
| _ _|
/`ミ _x 彡
/ |
/ ヽ ?
/ ̄| | | |
| ( ̄ヽ__ヽ_)_)
\二つ
*/
#include<bits/stdc++.h>
using namespace std;
long long read()
{
long long x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
return x * f;
}
int n;
int a[2000010];
int cnt, maxn = -0x3f3f3f3f;
int b[2000010];
long long ans;
int main()
{
n = read();
a[0] = 0;
for(int i = 1; i <= n; i++) a[i] = read();
for(int i = 1; i <= n; i++)
{
if(a[i] >= 0 && a[i - 1] < 0)
{
b[++cnt] = maxn;
maxn = -0x3f3f3f3f;
b[++cnt] = a[i];
}
if(a[i] < 0)
{
maxn = max(maxn, a[i]);
}
if(a[i] >= 0 && a[i - 1] >= 0) b[++cnt] = a[i];
}
if(maxn != -0x3f3f3f3f && b[cnt] >= 0) b[++cnt] = maxn;
for(int i = 2; i <= cnt; i++)
{
ans += max(b[i], b[i - 1]);
}
cout << ans << "\n";
cout << cnt << "\n";
for(int i = 1; i <= cnt; i++)
{
cout << b[i] << " ";
}
return 0;
}
T3
35分写法:
直接 \(n^2\) 暴力建图,邻接矩阵判重 + 链式前向星存图
建完图直接跑最短路就行
如果 \(n\) > \(10^4\) 直接输出 \(-1\)
考场上数组开小挂掉 \(10\) 分
原因: 因为最大可能有 \(n^2\) 条边,而数组只开到了 \(m\)
代码如下:
/*
/> フ
| _ _|
/`ミ _x 彡
/ |
/ ヽ ?
/ ̄| | | |
| ( ̄ヽ__ヽ_)_)
\二つ
*/
#include<bits/stdc++.h>
using namespace std;
long long read()
{
long long x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
return x * f;
}
int n, m, tot;
int head[100010], ver[100010], nex[100010], edge[100010];
int a[100010], b[100010], c[100010];
int e[1010][1010], d[1010];
bool v[1010];
void add(int x, int y, int z)
{
ver[++tot] = y;
nex[tot] = head[x];
head[x] = tot;
edge[tot] = z;
}
void dijkstra()
{
memset(d, 0x3f, sizeof(d));
priority_queue<pair<int,int> > q;
d[1] = 0;
q.push({0, 1});
while(!q.empty())
{
int x = q.top().second;
q.pop();
if(v[x]) continue;
v[x] = 1;
for(int i = head[x]; i; i = nex[i])
{
int y = ver[i];
if(d[y] > d[x] + edge[i])
{
d[y] = d[x] + edge[i];
q.push({-d[y], y});
}
}
}
}
int main()
{
memset(e, 0x3f, sizeof(e));
n = read(), m = read();
if(n > 1e4)
{
cout << -1;
return 0;
}
for(int i = 1; i <= n; i++)
{
a[i] = read();
b[i] = read();
c[i] = read();
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(i == j) continue;
if((a[i] ^ a[j]) >= b[i])
{
e[i][j] = min(e[i][j], c[i] +c[j]);
}
}
}
for(int i = 1; i <= m; i++)
{
int x = read(), y = read(), z = read();
e[x][y] = min(e[x][y], z);
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(i == j) continue;
if(e[i][j] != 0x3f3f3f3f)
{
add(i, j, e[i][j]);
}
}
}
dijkstra();
if(d[n] == 0x3f3f3f3f) cout << -1;
else cout << d[n];
return 0;
}
T4
标签:ch,++,18,long,int,while,&&,2022.11 From: https://www.cnblogs.com/Han-han-/p/16905472.html