#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int a[N] = {0};
int main(int argc, char const *argv[])
{
int T;
ios::sync_with_stdio(false);
cin>>T;
while(T--)
{
int n,k;
cin>>n;
int num=0;
int flag = 0;
int temp = 0;
for (int i = 0; i < n; ++i)
{
cin>>a[i];
if (a[i]&1)
{
num++;
}
if (i==0)
{
temp=a[i];
}
}
if (num<n&&num>=1||num==n&&n&1)
{
cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;
}
return 0;
}
每次不花个位数上的钱就可以
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc, char const *argv[])
{
int T;
ios::sync_with_stdio(false);
cin>>T;
while(T--)
{
int n;
cin>>n;
ll ans = 0;
int temp = n;
int k = 1;
int t = 1;
while(n>=10)
{
ans += (n/10)*10; //花更多
n = n-(n/10)*10+n/10;
}
ans += n;
cout<<ans<<endl;
}
return 0;
}
消除一段而不影响终点,相当于删除的这一段走的其实是一个圈
建立map映射点和这段序列的下标即可
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
char a[N];
map<pair<int,int>,int> mp;
int main(int argc, char const *argv[])
{
int T;
cin>>T;
while(T--)
{
int n = 0;
cin>>n;
cin>>a;
int ansl=0,ansr=0;
int t=0,m=1e9+10;
mp.clear();
pair<int,int> temp;
//mp[temp]=1;
for (int i = 0; i < n; ++i)
{
if (a[i]=='L')
{
temp.first -= 1;
}
if (a[i]=='R')
{
temp.first = temp.first+1;
}
if (a[i]=='U')
{
temp.second = temp.second+1;
}
if (a[i]=='D')
{
temp.second =temp.second- 1;
}
//cout<<temp.first<<" "<<temp.second<<endl;
if (mp[temp]>0&&i+1-mp[temp]<m||temp==make_pair(0,0)&&i+1-mp[temp]<m)
{
ansl = mp[temp]+1;
ansr = i+1;
m = i+1-mp[temp];
}
mp[temp]=i+1;
}
if (m<1e9+10)
{
cout<<ansl<<" "<<ansr<<endl;
}
else
cout<<"-1"<<endl;
}
return 0;
}
预处理所有妖怪的生命值,算出所需要的跳过的次数,排序后遍历即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
int hp[N] = {0};
vector<int > v;
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int n,a,b,k;
ll ans = 0;
cin>>n>>a>>b>>k;
for (int i = 0; i < n; ++i)
{
cin>>hp[i];
}
for (int i = 0; i < n; ++i)
{
if (hp[i]%(a+b)>0&&hp[i]%(a+b)<=a)
{
ans++;
}
else if(hp[i]%(a+b)==0)
{
int gap = b;
if (gap%a==0)
{
v.push_back(gap/a);
}
else
v.push_back(b/a+1);
}
else
{
int temp = (hp[i]%(a+b)-a);
if (temp%a==0)
{
v.push_back(temp/a);
}
else
v.push_back(temp/a+1);
}
}
sort(v.begin(),v.end());
for (int i = 0; i < v.size(); ++i)
{
k-=v[i];
if (k>=0)
{
ans++;
}
else
break;
}
cout<<ans<<endl;
return 0;
}