signed main()
{
int T=read();
while(T--)
{
re int cnt=0;
n=read();
scanf("%s",s+1);
dfor(i,1,n) s[i]=='1'?++cnt:0;
cnt==n?puts("NO"):puts("YES");
}
return 0;
}
int n,p,l,t;
signed main()
{
int T=read();
while(T--)
{
n=read(),p=read(),l=read(),t=read();
re int d=(t<<1)+l,s=n/7+(n%7?1:0),d1=0;
if(s&1) d1=t+l;
s>>=1;
re int l1=1,r1=s,ans=s;
while(l1<=r1)
{
int mid=(l1+r1)>>1;
if(mid*d>=p) ans=mid,r1=mid-1;
else l1=mid+1;
}
if(ans*d>=p) writeln(n-ans);
else if(ans*d+d1>=p) writeln(n-ans-1);
else
{
p-=ans*d+d1;
writeln(n-p/l-(p%l?1:0)-(d1?1:0)-ans);
}
}
return 0;
}
int n,a[N];
int gcd(int x,int y)
{
return y?gcd(y,x%y):x;
}
signed main()
{
int T=read();
while(T--)
{
n=read();
dfor(i,1,n) a[i]=read();
if(n==1){puts("1");continue;}
sort(a+1,a+n+1);
re int GCD=a[n]-a[n-1];
dforr(i,n-1,2) GCD=gcd(GCD,a[i]-a[i-1]);
re int sum=0;
re bool f=0;
dforr(i,n,2)
{
sum+=(a[n]-a[i-1])/GCD;
if(a[i]-a[i-1]>GCD&&!f) sum+=(a[n]-a[i])/GCD+1,f=1;
}
if(f) writeln(sum);
else writeln(sum+(a[n]-a[1])/GCD+1);
}
return 0;
}
这题我看了官方题解代码与官方题解相似度 < 100 % <100\% <100%
值得一提的是 l a m b d a lambda lambda 的使用是我从未接触的新大陆,现在及以后将会给我带来极大的便利
int n,q;
char s[N];
signed main()
{
n=read(),q=read();
scanf("%s",s+1);
vector<pair<int ,int > > ve;
ve.push_back(make_pair(0,0));
dfor(i,1,n)
{
int x=ve[i-1].first+(s[i]=='R')-(s[i]=='L');
int y=ve[i-1].second+(s[i]=='U')-(s[i]=='D');
ve.push_back(make_pair(x,y));
}
map<pair<int ,int > ,vector<int > > mp;
dfor(i,0,n) mp[ve[i]].push_back(i);
auto check = [&](pair<int ,int > p,int l,int r)
{
if(!mp.count(p)) return false;
auto it=lower_bound(mp[p].begin(), mp[p].end(), l);
return it!=mp[p].end()&&*it<=r;
};
while(q--)
{
int x,y,l,r;
x=read(),y=read(),l=read(),r=read();
int xx=ve[r].first+ve[l-1].first-x,yy=ve[r].second+ve[l-1].second-y;
bool f=check({x,y},0,l-1)|check({xx,yy},l,r-1)|check({x,y},r,n);
f?puts("YES"):puts("NO");
}
return 0;
}
我感觉其实比D简单
int n,q,tot,cnt[N],trip[N][26];
void ins(string s)
{
int x,p=0;
dfor(i,0,s.size()-1)
{
x=s[i]-'a';
if(!trip[p][x]) trip[p][x]=++tot;
p=trip[p][x],++cnt[p];
}
}
int query(string s)
{
int x,p=0,ans=0;
dfor(i,0,s.size()-1)
{
x=s[i]-'a';
p=trip[p][x];
ans+=cnt[p];
if(!p) return ans;
}
return ans;
}
signed main()
{
n=read();
vector<string > ve;
string s;
int sum=0;
dfor(i,1,n)
{
cin>>s;
sum+=s.size(),ve.push_back(s);
ins(s);
}
int ans=0;
dfor(i,0,ve.size()-1)
{
reverse(ve[i].begin(),ve[i].end());
ans+=n*ve[i].size()+sum-(query(ve[i])<<1);
}
write(ans);
return 0;
}