A.Foregone Solution
因为肯定有4,只要把4那位减1出来就行了。。。抱歉我是个傻子,退役太久,智商为负,写了个又麻烦又低效的东西,不想改了贴在这里纪念下sb时刻
#include<bits/stdc++.h>
#define mpi(i,j) make_pair(i,j)
using namespace std;
typedef pair<int,int> pll;
char str[105];
pll sol[10][2];
int ans[105][2][2];
int s[105][2];
int main(){
int t;
scanf("%d",&t);
for(int i=0;i<10;i++){
sol[i][0]=sol[i][1]=mpi(-1,-1);
}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
if(i==4||j==4)continue;
int p=i+j;
if(p>=10)sol[p%10][1]=mpi(i,j);
else sol[p][0]=mpi(i,j);
}
}
for(int cas=1;cas<=t;cas++){
scanf("%s",str);
int ls=strlen(str);
int cnt=0;
for(int i=ls-1;i>=0;i--){
int p=str[i]-'0';
if(i!=ls-1){
if((ans[i+1][1][0]||ans[i+1][1][1])){
ans[i][0][1]=sol[(p+9)%10][0].first==-1?0:1;
ans[i][1][1]=sol[(p+9)%10][1].first==-1?0:1;
}
if((ans[i+1][0][0]||ans[i+1][0][1])){
ans[i][0][0]=sol[p][0].first==-1?0:1;
ans[i][1][0]=sol[p][1].first==-1?0:1;
}
}else{
ans[i][0][0]=sol[p][0].first==-1?0:1;
ans[i][1][0]=sol[p][1].first==-1?0:1;
}
}
int up=0;
for(int i=0;i<ls;i++){
int p=str[i]-'0';
for(int j=0;j<((i==ls-1)?1:2);j++){
if(ans[i][up][j]){
s[i][0]=sol[(p-j+10)%10][up].first;
s[i][1]=sol[(p-j+10)%10][up].second;
up=j;break;
}
}
}
printf("Case #%d: ",cas);
int st;
st=0;while(!s[st][0])st++;
for(int i=st;i<ls;i++)printf("%d",s[i][0]);printf(" ");
st=0;while(!s[st][1])st++;
for(int i=st;i<ls;i++)printf("%d",s[i][1]);printf("\n");
}
return 0;
}
B.You Can Go Your Own Way
只需要E<=>S
#include<bits/stdc++.h>
using namespace std;
char str[100005];
int main(){
int t;
scanf("%d",&t);
for(int cas=1;cas<=t;cas++){
int n;
printf("Case #%d: ",cas);
scanf("%d%s",&n,str);
for(int i=0;i<2*n-2;i++){
if(str[i]=='S')printf("E");
else printf("S");
}puts("");
}
return 0;
}
C.Cryptopangrams
假设
a
b
c
a\ b\ c
a b c均为质数且
a
≠
c
a \neq c
a̸=c则
g
c
d
(
a
∗
b
,
b
∗
c
)
=
b
gcd(a*b,b*c)=b
gcd(a∗b,b∗c)=b
import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class Solution
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
BigInteger mul[] = new BigInteger[105];
BigInteger ans[] = new BigInteger[105];
BigInteger ans2[] = new BigInteger[105];
Map<BigInteger, Character> mic = new HashMap<BigInteger, Character>();
int t = in.nextInt();
for(int cas = 1; cas <= t; ++cas)
{
System.out.print("Case #"+cas+": ");
BigInteger n=in.nextBigInteger();
int l=in.nextInt(),split=2,cnt=0;mic.clear();
for(int i=1;i<=l;i++)mul[i]=in.nextBigInteger();
while(split<=l){if(!mul[split].equals(mul[split-1]))break;split++;}
ans2[split]=ans[split]=mul[split].gcd(mul[split-1]);
for(int i=split-1;i>=1;i--)ans2[i]=ans[i]=mul[i].divide(ans[i+1]);
for(int i=split+1;i<=l+1;i++)ans2[i]=ans[i]=mul[i-1].divide(ans[i-1]);
Arrays.sort(ans2,1,l+2);
for(int i=1;i<=l+1;i++){
if(mic.containsKey(ans2[i]))continue;
mic.put(ans2[i],(char)('A'+cnt++));
}
for(int i=1;i<=l+1;i++)System.out.print(mic.get(ans[i]));
System.out.println("");
}
}
}
需要用到大数,学习了一下java
- Array.sort(object,st,ed);(左闭右开)
- Map<BigInteger,Charactor>xx = new HashMap<BigInteger,Charactor>
- xx.containsKey/.get/.put
- 强制转换