A
核心思路:这题没什么好说的直接面向样例编程。
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
int mod = 1e9 + 7;
const int N = 1e3+10;
void solve()
{
LL n, m;
cin >> n >> m;
if ((n + m) % 2)
cout << "Burenka" << endl;
else
cout << "Tonya" << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
B
核心思路:咋一看这一题不知道怎么入手其实不需要慌我们先从最基本的情况入手。
我们其实可以从样例中发现一个很重要的规律:那就是我们构造的数对都是相差为1的奇偶数。
我们需要的是\((a+k)*b|4\).我们可以先列举最基本的情况:
k=1时
(1+1)*2=4
(3+1)*4=12
(5+1)*6=24
所以我们可以使用数学归纳法:k为奇数的时候,肯定是有解的。解就是那个数对
然后再来判断k为偶数的时候怎么办呢,什么时候有解,什么时候无解呢。
从样例知道10是有解的,所以我们来看他为什么是有解的.
其实很大的原因就是\((2+2+8)*3|4\),这是因为我们第一个凑出来的偶数已经很大了,所以即使后面是奇数也可以被整除。所以我们只需要保证k%4=2,那么我们肯定是可以凑出来4的倍数的,因为偶数最小也是2。
所以这道题就迎刃而解了。
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
int mod = 1e9 + 7;
const int N = 1e3+10;
void solve()
{
int n, k;
cin >> n >> k;
if (k % 2)
{
cout << "YES" << endl;
for (int i = 1;i <= n;i += 2)
{
cout << i << " " << i + 1 << endl;
}
}
else if (k % 4 == 2)
{
cout << "YES" << endl;
for (int i = 1;i <= n;i += 2)
{
if (i % 4==1)
{
cout << i + 1 << " " << i << endl;
}
else
cout << i << " " << i + 1 << endl;
}
}
else
cout << "NO" << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
C
核心思路:这里我们发掘一个很重要的性质:在a数组最大的数的后面的元素是怎么都不可以赢的。所以我们的回合可以定位在最大数的前面,因为最大数后面的回合都是他自己赢。这里的a数组中的元素是\(1\sim n\)哦。
有了这个思路之后,接下来该想着怎么去模拟呢。其实有个很烦的地方是那个询问,因为他问的是某个人在某个回合前赢的次数。所以我们采取离线询问,就是先把这个询问使用数组存起来,在逐渐访问。所以我们设置这个离线数组是有讲究的。我们开一个结构体使用两个变量来记录第几个访问和访问的人的编号.在使用ans来存储我们最终的答案。
知道这些细节就好做了.
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
int mod = 1e9 + 7;
const int N = 1e6+10;
int n, m, a[N];
struct Node
{
int p, id;
};
vector<Node> v[N];
int ans[N], cnt[N];
void solve()
{
cin >> n >> m;
int pos = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] == n) pos = i;
cnt[i] = 0;
v[i].clear();
}
int round = max(0, pos - 2);
for (int i = 1; i <= m; i++)
{
ans[i] = 0;
int p, k;
cin >> p >> k;
if (k <= round)
v[k].push_back({ p, i });
else if (p != pos) k = round, v[k].push_back({ p, i });
else if (p == pos)
{
ans[i] += k - round;//后面都是他赢.
k = round, v[k].push_back({ p, i });
}
}
int winner = 1;
for (int i = 2; i <= round + 1; i++)
{
int time = i - 1;
if (a[i] > a[winner])
{
winner = i;
cnt[i] ++;
}
else cnt[winner] ++;
for (auto it : v[time])
{
ans[it.id] += cnt[it.p];
}
}
for (int i = 1; i <= m; i++)
cout << ans[i] << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}
}
D
核心思路:这个主要是在与发现一个很重要的性质:如果一个区间的异或和是0,那么这个区间只需要进行len-1次操作就可以变成相同。这个是为什么呢,因为直接第一个第一个数异或上第二个然后一直异或上去就好了。
集合定义:\(dp[i]为以i结尾的序列需要操作的次数\)
集合划分:
- 存在一个点j,[i,j]的区间异或和是0,那么这个状态就可以转移到dp[i]
- 直接对a[i]这个点操作,所以dp[i-1]可以转移过来.(其实就是选不选对a[i]操作)
#include <bits/stdc++.h>
#define fi first
#define se second
#define endl '\n'
#define ios ios::sync_with_stdio(false); cin.tie(0), cout.tie(0)
typedef long long LL;
using namespace std;
const int N = 1e5 + 10,M = N*2;
void solve() {
int n;cin>>n;
vector<int> a(n+1),dp(n+1);
for(int i=1;i<=n;i++) cin>>a[i];
map<int,int> mp;
mp[0] = 0;dp[0] = 0;
for(int i=1;i<=n;i++)
{
a[i] ^= a[i-1];
dp[i] = dp[i-1] + 1;
if(mp.count(a[i])) dp[i] = min(dp[i],dp[mp[a[i]]]+i-mp[a[i]]-1);
mp[a[i]] = i;
}
cout<<dp[n]<<'\n';
}
int main()
{
ios;
int T=1;
cin>>T;
while(T -- ) {
solve();
}
return 0;
}
标签:10,typedef,int,Codeforces,long,solve,Div,include,814
From: https://www.cnblogs.com/xyh-hnust666/p/17004425.html