这一道题注意读题,就是看
(The number of positive integers at most x with the same number of digits as x)
意思是不超过x的和x位数相同的数的个数。
可以直接硬处理,龟速乘,不过取模是个大问题。
#include <iostream>
#define int long long
using namespace std;
int n;
const int mod = 998244353;
signed main() {
cin>>n;
int ans=0;
for(int m1=1;;m1*=10)
{
if( m1 <= n / 10 ){
if(m1>1) ans = (ans + (m1 * 9 % mod + 1 )%mod * ( m1 / 2 * 9 % mod) % mod )%mod;
else ans+=45;
}
else{
int a = 1,b = n - m1 + 1;
//b为奇数
if(b & 1) ans = ( ans + ( a + b ) / 2 % mod * ( b % mod ) ) % mod;
else ans = ( ans + (a+b) % mod * ( b / 2 % mod ) ) % mod;
break;
}
}
printf("%lld",ans);
return 0;
}
这个题目好像用结论很快很快就可以搞出来
- x AND y=a
- x+y=s
结论:
x+y = 2(x&y) + (x^y);
(x&y)&(x^y)=0;
所以知道s也就是x+y
还知道a,也就是
x+y - 2*(x&y) = x ^ y;
a 就是 x & y
所以bitwise(AND)就是“&”运算
很自然的把结论一用就可:
#include <iostream>
#define int long long
using namespace std;
int n;
const int mod = 998244353;
signed main() {
int t;cin>>t;
while(t--)
{
int a,s;
cin>>a>>s;
if((s>=2*a)&&(((s-2*a)&a)==0))
{
printf("Yes");
}else{
printf("No");
}
}
return 0;
}
并查集,不过要细微的操作。
要考虑到 1 1 2 2 3 3这样的数据,所以必然要用find(l-1),find(0)
#include <iostream>
#define int long long
using namespace std;
int n,Q;
const int mod = 998244353;
const int N = 2e5+10;
int f[N];
int find(int x)
{
if(x != f[x]) f[x] = find(f[x]);
return f[x];
}
signed main() {
int flag=0;
cin>>n>>Q;
for(int i=1;i<=n;i++)
{
f[i]=i;
}
while(Q--)
{
int l,r;
cin>>l>>r;
int l1 = find(l-1);
int r1 = find(r);
if(l1!=r1)
{
f[l1]=r1;
}
}
if(find(0)==find(n)) flag=1;
if(flag) printf("Yes");
else printf("No");
return 0;
}