难得AB出的还算比较快,被C的0~n-1调了1h,一首凉凉送给自己。
作者太菜,所以只有前三题的题解,抱歉。
Sol:
直接按题意模拟即可
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#define rg register
#define il inline
#define vd void
#define ll long long
#define For(i,x,y) for (rg int i=(x);i<=(y);i++)
#define Dow(i,x,y) for (rg int i=(x);i>=(y);i--)
#define cross(i,k) for (rg int i=first[k];i;i=last[i])
using namespace std;
il ll max(ll x,ll y){return x>y?x:y;}
il ll min(ll x,ll y){return x<y?x:y;}
il ll read(){
ll x=0;int ch=getchar(),f=1;
while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
if (ch=='-'){f=-1;ch=getchar();}
while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
int n,x,ans;
ll m;
char c[20];
int main(){
n=read(),m=read();
For(i,1,n){
scanf("%s",c),x=read();
if (c[0]=='+') m+=1ll*x;
else if (m<x) ans++;
else m-=x;
}
printf("%lld %d",m,ans);
}
Sol:
n只有100,根据冒泡排序我们可以知道,最多交换n^2次,而题目里的上限是2w。
所以直接模拟。
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#define rg register
#define il inline
#define vd void
#define ll long long
#define N 101
#define For(i,x,y) for (rg int i=(x);i<=(y);i++)
#define Dow(i,x,y) for (rg int i=(x);i>=(y);i--)
#define cross(i,k) for (rg int i=first[k];i;i=last[i])
using namespace std;
il ll max(ll x,ll y){return x>y?x:y;}
il ll min(ll x,ll y){return x<y?x:y;}
il ll read(){
ll x=0;int ch=getchar(),f=1;
while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
if (ch=='-'){f=-1;ch=getchar();}
while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
int n,x,a[N],b[N];
int main(){
n=read();
For(i,1,n) a[i]=b[i]=read();
sort(b+1,b+1+n);
Dow(i,n,1){
if (a[i]==b[i]) continue;
Dow(j,i-1,1)
if (a[j]==b[i]){
x=j;
break;
}
For(j,x,i-1){
printf("%d %d
",j,j+1);
swap(a[j],a[j+1]);
}
}
}
Sol:
因为不能有重复的数出现,而且一共就7个数字,所以n-1转成七进制的位数+m-1转成七进制的位数大于7就直接输出0,否则dfs。
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#define rg register
#define il inline
#define vd void
#define ll long long
#define For(i,x,y) for (rg int i=(x);i<=(y);i++)
#define Dow(i,x,y) for (rg int i=(x);i>=(y);i--)
#define cross(i,k) for (rg int i=first[k];i;i=last[i])
using namespace std;
il ll max(ll x,ll y){return x>y?x:y;}
il ll min(ll x,ll y){return x<y?x:y;}
il ll read(){
ll x=0;int ch=getchar(),f=1;
while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
if (ch=='-'){f=-1;ch=getchar();}
while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
int n,m,ans,a[20],b[20];
bool vis[10];
il vd Dfs(int k,bool flag){
if (k>b[0]){ans++;return;}
int l=flag?b[b[0]-k+1]:6;
For(i,0,l)
if (!vis[i]){
vis[i]=1;
Dfs(k+1,flag&&i==b[b[0]-k+1]?1:0);
vis[i]=0;
}
}
il vd dfs(int k,bool flag){
if (k>a[0]){Dfs(1,1);return;}
int l=flag?a[a[0]-k+1]:6;
For(i,0,l)
if (!vis[i]){
vis[i]=1;
dfs(k+1,flag&&i==a[a[0]-k+1]?1:0);
vis[i]=0;
}
}
int main(){
n=read()-1,m=read()-1;
if (!n) a[0]=1;
while (n) a[++a[0]]=n%7,n/=7;
if (!m) b[0]=1;
while (m) b[++b[0]]=m%7,m/=7;
if (a[0]+b[0]>7) printf("0");
else dfs(1,1),printf("%d",ans);
}