A: 直接遍历即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>PII;
const int N = 2e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
int n, m;
int main()
{
cin >> n;
int cnt = 0;
for(int i = 0; i <= n; i ++)
{
if((i ^ (2 * i) ^ (3 * i)) == 0) cnt ++;
}
cout << cnt << endl;
return 0;
}
B:模拟,转置得性质a[i][j] = a[j][i], 模拟一些即可
#include <iostream>
using namespace std;
int main()
{
int m,n;
int a[501][501];
int i,j;
cin>>m>>n;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
cin>>a[i][j];
cout << n << " " << m << endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
cout<<a[j][i]<<" ";
cout<<endl;
}
return 0;
}
C:二分枚举这个最大得距离,然后for循环遍历这些隔间之间得距离差,最后枚举出来即可:
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
int n, c;
int a[N];
bool check(int x)
{
int cnt = 1, mins = a[1];
for(int i = 2; i <= n; i ++)
{
if(a[i] - mins >= x)
{
cnt ++;
mins = a[i];
}
}
if(cnt >= c) return true;
else return false;
}
int main()
{
cin >> n >> c;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
}
sort(a + 1, a + 1 + n);
int l = 0, r = a[n] - a[1] + 1;
while(l + 1 != r)
{
int mid = l + r >> 1;
if(check(mid)) l = mid;
else r = mid;
}
cout << l << endl;
return 0;
}
D:shishan模拟,根据题意模拟即可,不要求思维含量:
#include<iostream>
using namespace std;
#include<algorithm>
string yw[30]={"","one","two","three","four","five","six","seven",
"eight","nine","ten","elven","twelve","thirteen","fourteen","fifteen",
"sixteen","seventeen","eighteen","nineteen","twenty","a","both",
"another","first","second","third"};
int sz[30]={0,1,4,9,16,25,36,49,64,81,0,21,44,69,96,25,56,89,24,61,0,
1,4,1,1,4,9};
int k;
int a[10];
int main()
{
for(int i=1;i<=6;i++){
string x;
cin>>x;
for(int j=1;j<=26;j++){
if(yw[j]==x){
a[++k]=sz[j];break;
}
}
}
if(k==0){cout<<0<<endl;return 0;}
sort(a+1,a+k+1);
for(int i=1;i<=k;i++){
if(i!=1&&a[i]<10)cout<<0;
cout<<a[i];
}
cout<<endl;
return 0;
}
E:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int ,int>PII;
const ll N = 3e5 + 5,M = 3e5;
const ll mod = 1e9 + 7;
ll n , a, b, ni[N];
ll kmi(ll a, ll b)
{
ll res = 1;
while(b){
if(b & 1){
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
ll C(ll n , ll m)
{
ll ans = 1;
for(int i = 1;i <= m;i ++)
{
ans = ans * (n - m + i) % mod * ni[i]%mod;
}
return ans;
}
int main(){
cin >> n >> a >> b;
for(int i = 1;i <= M;i ++)ni[i] = kmi(i,mod - 2);
ll ans = (kmi(2, n) - C(n ,a) - C(n, b) - 1 + 3 * mod)%mod;
printf("%lld",ans);
return 0;
}