答案在最下方
A
这题是个简单的暴力,注意每一个编号只能选择一次,不能直接全选最大。直接枚举出20^5种可能,维护一个最大数出来即可。当然也可以直接拿眼看,因为数据范围非常小。
#include<bits/stdc++.h>
using namespace std;
int a[21],b[21],c[21],d[21],e[21];
int main(){
int ans,res=-1;
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
for(int k=1;k<=20;k++){
for(int m=1;m<=20;m++){
for(int n=1;n<=20;n++){
if(i!=j&&j!=k&&k!=m&&m!=n){
ans=a[i]+b[j]+c[k]+d[m]+e[n];
res=max(ans,res);
}
}
}
}
}
}
cout<<res;
return 0;
}
B
这题我开始写的模拟,网上有很多思路比我简单,我开始想的是一位字母能代表26个,两位字母能代表702个,三位字母包含2019,我模拟出每一个i对应的字符串是什么,遇到Z就当前位重置为A,上一位加一,和加法的原理差不多,把十位变成了二十六位进制。
#include<bits/stdc++.h>
using namespace std;
int main(){
string ans[2020];
for(int i=1;i<=26;i++){
ans[i]='A'+i-1;
cout<<i<<" "<<ans[i]<<endl;
}
int cnt=0;
int temp=0;
for(int i=27;i<=702;i++){
ans[i]='A'+cnt;
int tem=i;
ans[i]+='A'+tem-27-26*temp;
if(ans[i][1]=='Z'){
cnt++;
temp++;
}
cout<<i<<" "<<ans[i]<<endl;
}
int cn=0;
cnt=0;
temp=0;
for(int i=703;i<=2019;i++){
ans[i]='A'+cnt;
ans[i]+='A'+cn;
int tem=i;
ans[i]+='A'+tem-703-26*temp;
if(ans[i][1]=='Z'&&ans[i][2]=='Z'){
cnt++;
temp++;
cn=0;
continue;
}
if(ans[i][2]=='Z'){
cn++;
temp++;
}
cout<<i<<" "<<ans[i]<<endl;
}
return 0;
}
C
写个递推结束。
因为只要后四位,取模后四位的值就行。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=20190324;
ll a[maxn];
int main(){
a[1]=1;
a[2]=1;
a[3]=1;
for(int i=4;i<=maxn;i++){
a[i]=a[i-1]+a[i-2]+a[i-3];
a[i]%=10000;
}
cout<<a[maxn]%10000;
return 0;
}
D
直接三个数暴力,唯一的坑点就是三个数排序之后要有本质不同,所以在循环的过程中直接让 i<j<t 就好,避免踩坑。做个累加和结束。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll ans=0;
for(int i=1;i<2019;i++){
for(int j=i+1;j<2019;j++){
int t=2019-i-j;
if(t<j) continue;
int f=1;
int a=i,b=j;
while(a){
if(a%10==2||a%10==4){
f=0;
break;
}
a/=10;
}
while(b){
if(b%10==2||b%10==4){
f=0;
break;
}
b/=10;
}
while(t){
if(t%10==2||t%10==4){
f=0;
break;
}
t/=10;
}
if(f) ans++;
}
}
cout<<ans;
return 0;
}
E
先处理一下数据,给的txt文本是连在一起的,我直接读入了,我还纳闷咋读不进去,原来当成一个值了。
01010101001011001001010110010110100100001000101010
00001000100000101010010000100000001001100110100101
01111011010010001000001101001011100011000000010000
01000000001010100011010000101000001010101011001011
00011111000000101000010010100010100000101100000000
11001000110101000010101100011010011010101011110111
00011011010101001001001010000001000101001110000000
10100000101000100110101010111110011000010000111010
00111000001010100001100010000001000101001100001001
11000110100001110010001001010101010101010001101000
00010000100100000101001010101110100010101010000101
11100100101001001000010000010101010100100100010100
00000010000000101011001111010001100000101010100011
10101010011100001000011000010110011110110100001000
10101010100001101010100101000010100000111011101001
10000000101100010000101100101101001011100000000100
10101001000000010100100001000100000100011110101001
00101001010101101001010100011010101101110000110101
11001010000100001100000010100101000001000111000010
00001000110000110101101000000100101001001000011101
10100101000101000000001110110010110101101010100001
00101000010000110101010000100010001001000100010101
10100001000110010001000010101001010101011111010010
00000100101000000110010100101001000001000000000010
11010000001001110111001001000011101001011011101000
00000110100010001000100000001000011101000000110011
10101000101000100010001111100010101001010000001000
10000010100101001010110000000100101010001011101000
00111100001000010000000110111000000001000000001011
10000001100111010111010001000110111010101101111000
#include<bits/stdc++.h>
using namespace std;
int main(){
string s[50];
for(int i=0;i<30;i++){
cin>>s[i];
}
for(int i=0;i<30;i++){
for(int j=0;j<s[i].size();j++){
cout<<s[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
还有什么呢,dfs跑一遍记录中间位置就好了。
最后根据中间位置做判断,每两个坐标相减看上一次的操作是啥。
做麻烦了,毕竟填空题。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=55;
int ans;
int f=0;
int dir[4][2]={
{-1,0},{1,0},{0,-1},{0,1}
};
struct node{
int x,y;
}path[maxn*maxn],now;
int a[maxn][maxn];
int vis[maxn][maxn];
void output(){
f=1;
string s;
int tx=0,ty=0;
for(int i=1;i<=ans;i++){
//cout<<path[i].x<<" "<<path[i].y<<endl;
int px=path[i].x-tx;
int py=path[i].y-ty;
if(px==-1&&py==0) s+='U';
else if(px==1&&py==0) s+='D';
else if(px==0&&py==-1) s+='L';
else if(px==0&&py==1) s+='R';
tx=path[i].x;
ty=path[i].y;
}
cout<<s<<endl;
return ;
}
bool judge(int x,int y){
if(x>=1&&y>=1&&x<=30&&y<=50&&vis[x][y]!=1&&a[x][y]!=1){
return 1;
}
return 0;
}
void dfs(int x,int y,int step){
if(x==30&&y==50){
ans=step;
now.x=30;
now.y=50;
path[step]=now;
if(!f) output();
return ;
}
for(int i=0;i<4;i++){
int xx=x+dir[i][0];
int yy=y+dir[i][1];
now.x=xx;
now.y=yy;
if(judge(xx,yy)){
vis[xx][yy]=1;
path[step]=now;
dfs(xx,yy,step+1);
vis[xx][yy]=0;
}
}
}
int main(){
memset(a,0,sizeof(a));
memset(vis,0,sizeof(vis));
for(int i=1;i<=30;i++){
for(int j=1;j<=50;j++){
cin>>a[i][j];
}
getchar();
}
dfs(1,1,0);
//cout<<ans;
return 0;
}
A答案是:490
B答案是:BYQ
C答案是:4659
D答案是:40891
E答案是:DDRRURRRRRRDRRRUUURRDDDLDDDLDDLDLUULLDDDDDDDLDDLUUUUULULDDDDDDDDDDDDLDDLDDDDRRRRRURUUUUULUUUURURUURUURRRDDDDDDDLLULLDDRDDDRRUURRURDRRUUURRUUUUULUUUURRRUURURRDDDRRRDDDRDDLDLDDDDDDLDDLLLDLLULLDDDRRRRRURRRRRUUUUUURURDDDDDRRDDDRRRRUURUUUUUUUULLLUUUURRRRUUULDLLUUUULLUUULUULLUURRRRDDDRRUUURURRRDDRRRRRDDRRDDLLLDDRRDDLDLDDRRDDLLDDLLLDLDDDLDDDDDDDRRRUUUUURRRRRURDDDDDDDRR(不知道对不对,自己生成的,最近真的都是错误答案)