直接判断单价和单买就可以
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()
int main(int argc, char const *argv[])
{
// #define DEBUG
#ifdef DEBUG
freopen("1.dat","r",stdin);
freopen("ans.dat","w",stdout);
#endif
LL _;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>_;
while(_--){
LL a,b,c;
cin>>a>>b>>c;
LL ans1=-1;
LL ans2=-1;
if(a<c)
ans1 = 1;
if(a*b>c)
ans2 = b;
cout<<ans1<<" "<<ans2<<endl;
}
return 0;
}
仔细思考会发现,少的那个总会被消除完的,因为不可能使得两个都有剩下而不相邻
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()
// const int N = 1e5+10;
// int a[N];
int main(int argc, char const *argv[])
{
// #define DEBUG
#ifdef DEBUG
freopen("1.dat","r",stdin);
freopen("ans.dat","w",stdout);
#endif
LL _;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>_;
while(_--){
// 少的那个总是可以消除完的
string s;
cin>>s;
int c = count(all(s),'0');
int c2 = s.length()-c;
c = min(c, c2);
if(c&1)
cout<<"DA"<<endl;
else
cout<<"NET"<<endl;
}
return 0;
}
记录一波前缀和,每次向后找更小的负数,记录到答案的cnt里就可以
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()
const int N = 1e6+10;
int a[N];
int main(int argc, char const *argv[])
{
// #define DEBUG
#ifdef DEBUG
freopen("1.dat","r",stdin);
freopen("ans.dat","w",stdout);
#endif
LL _;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>_;
while(_--){
string s;
cin>>s;
a[0]=0;
rep(i,1,s.length()+1)
if(s[i-1]=='+')
a[i]=a[i-1]+1;
else
a[i] =a[i-1]-1;
// 遇到的每一个负数,都是要进去一次的
LL ma = 0;
LL ans = 0;
LL used = 0;
rep(i,1,s.length()+1){
if(a[i]>=0)
continue;
if(a[i]<ma){
ans += i*(abs(a[i])-used);
used = abs(a[i]); // 用了a[i]次
ma = a[i];
// cout<<a[i]<<" "<<i<<endl;
}
}
ans += s.length();
cout<<ans<<endl;
}
return 0;
}