题目链接
md,要不是卡B卡了一个小时,铁上分,***。文明用语哦该,发泄一下也不为过吧,呜呜
先写D1,多给两分钟就能过,思路最后一分钟猜对了
- D1
- 思路
为什么不知道,可是就是猜对了,首先猜最多不会超过 2 2 2 次;大概意思就是一个位置删除之后反转的话会抵消好多。然后就猜奇偶,然后呢,还个 p p p 然后,就过了,多给两分钟就过了 - 代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){
cout<<s<<": "<<x<<endl;
}
#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
int vis[20],p[20];
void solve()
{
int n;cin>>n;int q;cin>>q;
string s;cin>>s;
vector<int> pre(n+1);
for(int i=1;i<n;i+=2){
if(s[i]=='+') s[i]='-';
else s[i]='+';
}
// cout<<s<<endl;
for(int i=0;i<n;i++){
if(s[i]=='+'){
pre[i+1]=pre[i]+1;
}
else{
pre[i+1]=pre[i]-1;
}
}
while(q--){
int l,r;cin>>l>>r;
if(l==r){
cout<<1<<endl;continue;
}
int k=abs(pre[r]-pre[l-1]);
//别忘了加个abs,负奇数给的是负一
if(k==0){
cout<<0<<endl;
}
//或者把这里改成if(k%2)
else if(k%2==1){
cout<<1<<endl;
}
else{
cout<<2<<endl;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("a.txt", "r", stdin);
freopen("aout.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
}
- A
- 思路
找最大的模后值,肯定在大于等于 n / 2 n/2 n/2 后面找。 - 代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){
cout<<s<<": "<<x<<endl;
}
#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
void solve()
{
ll l,r;cin>>l>>r;
if(r%2==0){
ll a=r;
ll b= max(r/2+1,l);
cout<<(a%b)<<endl;
}
else
{
ll a=r;
ll b=max(l,(r+1)/2);
cout<<(a%b)<<endl;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("a.txt", "r", stdin);
freopen("aout.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
}
- B
- 思路
md,就是因为他。
直接构造其实, 1 4 6 8 9 1 ~4~ ~6~ ~8~ 9 1 4 6 8 9 出现了,直接输出他们;0出现了输出 s [ 0 ] + 0 s[0]+0 s[0]+0;
如果 2 3 5 7 2 ~3~ 5~ 7 2 3 5 7出现了 2 2 2 次,直接输出xx;剩下的还有 27 57 ~27 ~57 27 57 没 537 537 537 wuwuuwuwuwuwuuw, 57 57 57 就够了。 - 代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){
cout<<s<<": "<<x<<endl;
}
#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
int vis[20],p[20];
void solve()
{
int k;cin>>k;
string s;cin>>s;
for(int i=0;i<10;i++){
vis[i]=0,p[i]=-1;
}
for(int i=0;i<s.size();i++){
int tx=s[i]-'0';
if(p[tx]==-1) p[tx]=i;
vis[tx]++;
}
if(vis[1]) {
cout<<1<<endl;cout<<1<<endl;return;
}
for(int i=4;i<=9;i+=2){
if(vis[i]){
cout<<1<<endl;
cout<<i<<endl;return;
}
}
if(vis[9]){
cout<<1<<endl;cout<<9<<endl;return;
}
if(vis[0]){
cout<<2<<endl;cout<<s[0]<<0<<endl;return;
}
if(vis[2]>=2){
cout<<2<<endl;cout<<22<<endl;return;
}
if(vis[3]>=2){
cout<<2<<endl;cout<<33<<endl;return;
}
if(vis[5]>=2){
cout<<2<<endl;cout<<55<<endl;return;
}
if(vis[7]>=2){
cout<<2<<endl;cout<<77<<endl;return;
}
if(vis[2]){
if(p[2]!=0){
cout<<2<<endl;
cout<<s[0]<<2<<endl;return;
}
}
if(vis[2]&&vis[7]&&p[2]<p[7]){
cout<<2<<endl;cout<<27<<endl;return;
}
if(vis[5]){
if(p[5]!=0){
cout<<2<<endl;
cout<<s[0]<<5<<endl;return;
}
}
if(vis[5]){
cout<<2<<endl;
cout<<57<<endl;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("a.txt", "r", stdin);
freopen("aout.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
}
- C
- 思路
如果全是 1 1 1,随便输出两个长度相等的;否则找到 0 0 0 的位置,输出,因为后面差个 0 0 0 ,正好是二倍的关系,前面差个 0 0 0,那就是相等。 - 代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
template<typename T>
void Debug(T x,string s){
cout<<s<<": "<<x<<endl;
}
#define PII pair<int,int>
#define x first
#define y second
#define PB push_back
int vis[20],p[20];
void solve()
{
int n;cin>>n;
string s;cin>>s;
int p=-1;
for(int i=0;i<n;i++){
if(s[i]=='0'){
p=i;break;
}
}
if(p==-1){
cout<<1<<" "<<n-1<<" "<<2<<" "<<n<<endl;return;
}
p++;
// cout<<p<<" "<<n/2<<endl;
// else{
if(p<=n/2){
cout<<p<<" "<<n<<" "<<p+1<<" "<<n<<endl;
}
else{
cout<<1<<" "<<p<<" "<<1<<" "<<p-1<<endl;
}
// }
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("a.txt", "r", stdin);
freopen("aout.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
}