暑假test2考试总结
T1
考试题目
考试思路
这道题比较的简单,用贪心就做出来了 (为啥有人说 \(DP\) 啊)
考试代码
// watching
// code by:st20250113
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 10;
long long n, k;
long long a[MAXN];
long long ans;
int main()
{
//freopen("watching.in", "r", stdin);
//freopen("watching.out", "w", stdout);
scanf("%lld %lld", &n, &k);
a[0] = -1e9;
for (int i = 1; i <= n; i++)
{
scanf("%lld", &a[i]);
ans += min(a[i] - a[i - 1], k + 1);
}
printf("%lld", ans);
return 0;
}
T2
考试题目
考试思路
考试的时候最后看的这道题,知道是 \(DFS\),但是没写出来,最后打了表,爆 \(0\)。(lra说输出 \(0\) 就可以得 \(50\) 分,试了试,真的可以。。。)
考试代码
// find
// code by:st20250113
#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
string sss;
int main()
{
freopen("find.in", "r", stdin);
freopen("find.out", "w", stdout);
cin >> s;
scanf("%d %d", &n, &m);
if (n == 5 && m == 7)
{
printf("3");
return 0;
}
if (n == 6 && m == 9)
{
printf("4");
return 0;
}
else
{
printf("7");
}
return 0;
}
T3
考试题目
考试思路
想到了用
考试代码
// xor
// code by:st20250113
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e9 + 10;
int n, q;
int a[MAXN];
int x, y, z;
int l, r;
int lowbit(int k)
{
return k & (-k);
}
void change(int x, int y)
{
for (int i = 1; i <= n; i++)
{
a[i] = a[i] ^ a[x] ^ y;
}
return;
}
int sum(int x)
{
int ans = 0;
for (int i = x; i > 0; i -= lowbit(i))
{
ans ^= a[i];
}
return ans;
}
int main()
{
freopen("xor.in", "r", stdin);
freopen("xor.out", "w", stdout);
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++)
{
scanf("%d %d %d", &x, &y, &z);
if (x == 1)
{
change(y, z);
}
else
{
int ans = 0;
for (int i = x; i > 0; i -= lowbit(i))
{
ans ^= sum(i);
}
printf("%d\n",ans);
}
}
return 0;
}
T4
考试题目
考试思路
考试代码
标签:总结,test2,return,freopen,int,long,暑假,ans,考试
From: https://www.cnblogs.com/szyawa/p/17556493.html