A:
模拟题
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll w,h,d;
cin>>w>>h>>d;
w-=d*2;
h-=d*2;
if(w<=0||h<=0)cout<<0<<endl;
else cout<<w*h<<endl;
return 0;
}
G:
判一下a-z是否都是偶数/奇数/其他即可
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
char s[M];
int mp[30];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>s;
int n=strlen(s);
for(int i=0;i<n;i++)mp[s[i]-'a']++;
int x=-1;
for(int i=0;i<26;i++)
{
if(mp[i]==0)continue;
// cout<<mp[i]<<endl;
if((x==-1||x==1)&&(mp[i]&1))x=1;
else if((x==-1||x==0)&&mp[i]%2==0)x=0;
else
{
x=2;
break;
}
}
cout<<x<<endl;
return 0;
}
B:
暴力每个字符串单独算下贡献就行
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
ll nm[30];
map<string,int>mp;
string s[M];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s[i],mp[s[i]]++,nm[s[i][0]-'A']++;
// cout<<"ok"<<endl;
}
ll ans=0;
for(int i=1;i<=n;i++)
ans+=nm[s[i][0]-'A']-mp[s[i]];
cout<<ans<<endl;
return 0;
}
C:
考虑不变的位置,最终不变的一定是数值连续上升子序列,
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
struct node
{
int l,r,op;
}P[M];
node q[M];
int a[M];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int x,n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>x,P[x].l=i,P[x].r=i,P[i].op=i;
for(int i=1;i<=n;i++)q[i].l=P[i].l,q[i].r=P[i].r,q[i].op=i;
int now=0,ma=0;
for(int i=1;i<=n;i++)
{
// cout<<q[i].l<<" "<<q[i].r<<" "<<q[i].op<<endl;
if(q[i].l>q[i-1].r)now++;
else now=1;
ma=max(now,ma);
}
cout<<n-ma<<endl;
return 0;
}
H:
暴力枚举0-999这1000个数,看每个数需要最少的按动次数
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
int mp[11];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,x;cin>>n;
for(int i=1;i<=n;i++)cin>>x,mp[x]=1;
cin>>x;
int mi=2000;
for(int i=0;i<=999;i++)
{
int k=i;
vector<int>v;v.clear();
v.pb(k%10);k/=10;
if(i>=10)v.pb(k%10);k/=10;
if(i>=100)v.pb(k%10);
bool f=true;
for(int j=0;j<v.size();j++)
{
if(mp[v[j]])
f=false;
}
if(!f)continue;//按不出这个数
else mi=min(mi,abs(x-i));
}
cout<<mi<<endl;
return 0;
}
D:
满足题意的x,一定是2或5的倍数,且是n的因子。
我们看n因子2有几次,5有几次,组合一下即可,不要忘了1。
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
ll lg2[M],lg5[M];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin>>n;
vector<ll>v;
int nm2=0,nm5=0;
while(n%2==0)n/=2,nm2++;
while(n%5==0)n/=5,nm5++;
ll tp=1,t=0;
while(tp<=1e18)lg2[t]=tp,tp*=2,t++;
t=0,tp=1;
while(tp<=1e18)lg5[t]=tp,tp*=5,t++;
for(int i=0;i<=nm2;i++)
for(int j=0;j<=nm5;j++)
v.pb(lg2[i]*lg5[j]);
sort(v.begin(),v.end());
cout<<v.size()<<endl;
for(int i=0;i<v.size();i++)
cout<<v[i]<<endl;
return 0;
}
K:
暴力连边+弗洛伊德找最短路即可
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
struct point{
double x,y;
}p[20][2];
double xmult(point p1,point p2,point p0){
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int dot_online_in(point p,point l1,point l2){
return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
}
int mp[100][100];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for(int j=0;j<=1;j++)
for(int i=1;i<=n;i++)cin>>p[i][j].x>>p[i][j].y;
memset(mp,0x3f,sizeof(mp));
for(int i=1;i<=n;i++)
for(int j=1+1;j<=n;j++)
{
mp[i][i]=0;
bool f=true;//ij可以传球
for(int k=1;k<=n;k++)
if(dot_online_in(p[k][1],p[i][0],p[j][0]))f=false;
int nm=1;
if(!f)continue;
for(int k=1;k<=n;k++)
{
if(k==i||k==j)continue;
if(dot_online_in(p[k][0],p[i][0],p[j][0]))nm++;
}
mp[i][j]=mp[j][i]=nm;//需要几次传球
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(mp[i][k]+mp[k][j] < mp[i][j]){
mp[i][j] = mp[i][k]+mp[k][j];
}
}
}
}
if(mp[1][n]>100000)cout<<-1<<endl;
else cout<<mp[1][n]<<endl;
return 0;
}