#include<bits/stdc++.h>usingnamespace std;typedeflonglong ll;typedef pair<ll, ll>PII;constint N =2e6+10;constint MOD =998244353;constint INF =0X3F3F3F3F;int n, m;intmain(){
cin >> n;int cnt =0;for(int i =0; i <= n; i ++){if((i ^(2* i)^(3* i))==0) cnt ++;}
cout << cnt << endl;return0;}
B:模拟,转置得性质a[i][j] = a[j][i], 模拟一些即可
#include<iostream>usingnamespace std;intmain(){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;}return0;}
C:二分枚举这个最大得距离,然后for循环遍历这些隔间之间得距离差,最后枚举出来即可:
#include<iostream>#include<algorithm>usingnamespace std;constint N =1e5+10;typedeflonglong ll;int n, c;int a[N];boolcheck(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)returntrue;//说明安排的距离小elsereturnfalse;// 说明安排的距离大}intmain(){
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;return0;}
#include<bits/stdc++.h>usingnamespace std;typedeflonglong 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;}intmain(){
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);return0;}
PS:不定期更新...... 目录
(1)无法关闭自动编译(Edit — Preference — General — Auto Refresh) (1)无法关闭自动编译(Edit — Preference — General — Auto Refresh࿰…