小雷的神奇电脑
同或和最大等于异或和最小。还有要记住min取第一项,不要取 inf 真的很烂。
如果要求异或和最小的话,先排个序,然后两两异或取最小就好,如果要求异或最大,那么网络上有力扣的题解可以看。
AcWing 143. 最大异或对_acwing.143-CSDN博客
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define Mod 998244353
#define PI acos(-1);
#define MAXN 210000
#define debug cout<<"debug:\t"
#define debugn cout<<"debug:\n"
#define enter cout<<"\n"
const int inf=0x3f3f3f3f;
vector<int>wei[35];
const int HIGH_BIT=30;
void solve(){
int n,m;
cin>>n>>m;
vector<int>a(n);
//任意两个不同的数字
for(int i=0;i<n;i++){
cin>>a[i];
}
//异或最小,同或就最大。
sort(a.begin(),a.end());
int min1=(1<<30)-1;
for(int i=1;i<n;i++){
if((a[i]^a[i-1])<min1){
min1=(a[i]^a[i-1]);
}
}
int y=1;
for(int i=0;i<m-1;i++){
y<<=1;
y|=1;
}
cout<<(y^min1)<<endl;
}
int main() {
// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
岗位分配
高中数学的插板法,原谅我已经是个大学生了。我不记得了。
已知每个志愿者之间没有区别,有不同的多个岗位且每个岗位至少有一个人,想到用组合数学隔板法来进行计数。 由于隔板法保证的是每个岗位至少分配一位志愿者,但是各个岗位的至少需求人数不一定为 1,故需要现在需求人数大于 的岗位进行处理:对于需求人数至少为 的岗位,提前插入 k-1 位志愿者,并计所有 提前插入的人数为 sum ,则对隔板的处理就是在 m-sum 的人数 m-sum-1 的空中加入隔板来分 组。同时,注意到会有空闲的情况,这种情况可以多出一个实际没有的岗位来放这些人。答案分两种情 况考虑,有空闲的情况,是在 n-sum-1 的空位中加入 n 个板子来完成
,没有空闲的情况 是
,相加即可。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define mod 998244353
#define PI acos(-1);
#define debug cout<<"debug:\t"
#define debugn cout<<"debug:\n"
#define enter cout<<"\n"
const ll inf=0x3f3f3f3f;
const ll maxn=2e5+5;
ll inv[maxn],fac[maxn];
ll quickPow(ll a,ll b){
ll ans=1;
while(b){
if(b&1)
ans=(ans*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return ans;
}
void init(){
//求阶乘
fac[0]=1;
for(int i=1;i<maxn;i++){
fac[i]=fac[i-1]*i%mod;
}
//求逆元
inv[maxn-1]=quickPow(fac[maxn-1],mod-2);
for(int i=maxn-2;i>=0;i--){
inv[i]=inv[i+1]*(i+1)%mod;
}
}
ll cc(int n,int m){
if(m>n){
return 0;
}
if(m==0)
return 1;
return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void solve(){
int n,m;
cin>>n>>m;
int sum=0;
for(int i=0;i<n;i++){
int a;
cin>>a;
sum+=a-1;
}
m-=sum;
cout<<(cc(m-1,n)+cc(m-1,n-1))%mod<<endl;
}
signed main() {
init();
// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
简单的素数
真的很简单。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define Mod 998244353
#define PI acos(-1);
#define MAXN 210000
#define debug cout<<"debug:\t"
#define debugn cout<<"debug:\n"
#define enter cout<<"\n"
bool su(int x){
if(x==1 or x==2){
return true;
}
for(int i=2;i*i<=x;i++){
if(x%i==0){
return false;
}
}
return true;
}
void solve(){
int n;
cin>>n;
if(su(n)){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
}
int main() {
// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
小雷的算式
字符串数字储存与运算的考察。
将字符串中的数字提取出来从大到小排序,然后从大到小加加号输出出来,同时将答案计算出来。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define Mod 998244353
#define PI acos(-1);
#define MAXN 210000
#define debug cout<<"debug:\t"
#define debugn cout<<"debug:\n"
#define enter cout<<"\n"
void solve(){
string s;
vector<int>a;
cin>>s;
int n=s.size();
int x=0;
for(int i=0;i<n;i++){
if(s[i]!='+'){
x=x*10+s[i]-'0';
}
if(s[i]=='+' or i==n-1){
a.push_back(x);
x=0;
}
}
sort(a.begin(),a.end());
reverse(a.begin(),a.end());
cout<<a[0];
int sum=a[0];
for(int i=1;i<a.size();i++){
cout<<"+"<<a[i];
sum+=a[i];
}
cout<<endl;
cout<<sum<<endl;
}
int main() {
// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
聪明且狡猾的恶魔
你只要记得,除了老大,只要剩下的 (n-1) 个恶魔里有超过半数可以获得一个硬币,这事就结束了。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define Mod 998244353
#define PI acos(-1);
#define MAXN 210000
#define debug cout<<"debug:\t"
#define debugn cout<<"debug:\n"
#define enter cout<<"\n"
void solve(){
int x,n;
cin>>x>>n;//有x枚金币,一共有n个恶魔。最小编号是老大。
if(n%2==0){
int z=n/2-1;
x-=z;
cout<<x<<endl;
return;
}else{
int z=n/2;
x-=z;
cout<<x<<endl;
return;
}
}
int main() {
// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}