目录
1、错误票据(13年省赛——3月23日)
注意:这道题恶心在输入,要吃回车或者空格,抑或是加空格,全部恶心的点都在输入
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000009
using namespace std;
typedef long long LL;
int n,idx,a[100010];
int main() {
int ss=0;
cin>>n;
getchar();//吃空格
while(n--) {
string s;
getline(cin,s);//getline用于输入字符串并吃回车
s+=' ';//加空格,用于字符串换成数字
//分解数字
for(int i=0; i<s.size(); i++) {
if(s[i]==' ') a[++idx]=ss,ss=0;
else ss=ss*10+(s[i]-'0');
}
}
int f1=0,f2=0;
sort(a+1,a+idx+1);//排序
for(int i=1; i<=idx; i++) {
if(a[i]==a[i+1]) f2=a[i+1];
if(a[i]+2==a[i+1]) f1=a[i]+1;
}
cout<<f1<<" "<<f2;
return 0;
}
2、取球游戏(12年省赛——3月10日)
博弈论dp,我先手,只要我先手的局面是输的,那么后继局面+1 +3 +7 +8就是我赢,以此类推即可
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000009
using namespace std;
typedef long long LL;
int n,a[10015];//1e4+8
int main() {
for(int i=1; i<=10000; i++) {//n<1e4
if(!a[i])
a[i+1]=a[i+3]=a[i+7]=a[i+8]=1;
}
cin>>n;
while(n--) {
int x;
cin>>x;
cout<<a[x]<<endl;
}
return 0;
}
3、方格分割(17年省赛——3月20日)
对称标记,回溯即可,由于旋转对称属于同一种方法,刚好4种,所以要/4
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000009
using namespace std;
typedef long long LL;
const int dr[]={0,0,-1,1};
const int dc[]={1,-1,0,0};
int vis[10][10];
int ans;
void dfs(int x,int y) {
if(x==0||x==6||y==0||y==6) {//到端点结束
ans++;
return;
}
for(int i=0; i<4; i++) {
int nx=x+dr[i];
int ny=y+dc[i];
if(nx<0 || ny<0 || nx>6 || ny>6 || vis[nx][ny]) continue;
vis[nx][ny]=vis[6-nx][6-ny]=1;//对称标记
dfs(nx,ny);
vis[nx][ny]=vis[6-nx][6-ny]=0;//对称回溯
}
}
int main() {
vis[3][3]=1;
dfs(3,3);
cout<<ans/4;//旋转对称
return 0;
}
4、数的幂次(3月17日)
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000009
using namespace std;
typedef long long LL;
LL n,m,p;
int quick() {
LL res=1;
int base=n;
while(m) {
if(m & 1) res=(res*base)%p;
base=(base*base)%p;
m/=2;
}
return res;
}
int main() {
int T;
cin>>T;
while(T--) {
cin>>n>>m>>p;
LL res=1;
LL base=n;
while(m) {
if(m & 1) res=(res*base)%p;
base=(base*base)%p;
m/=2;
}
cout<<res%p<<endl;
}
return 0;
}