hoj 13786 Equivalent Passwords

//题目看不懂 水题都不会做 感觉自己好傻逼
#include <iostream> #include <algorithm> #include <stdio.h> #include <queue> #include <limits.h> #include <string.h> #include <vector> #include <map> #include <math.h> #define LL unsigned long long #define INF 2100000000 #define fi first #define se second #define lowbit(x) (x&(-x)) #define eps 5e-7 using namespace std; const int maxn=(int)1e5 +30; const int MOD=(int)1e9+10; const double PI=acos(-1.0) ; char s[10]; int a[10]; int l; int getnum(){ int res=0; int i=0; while(s[l]){ res*=10; a[l]=s[l]-'0'; res+=a[l]; l++; } return res; } int n,t; bool vis[6][maxn]; void dfs(int pos,int num,int q){ num*=10; if(l==pos+1){ if(a[pos]+q<10) { vis[l][num+a[pos]+q]=true;//printf("%d ",num+a[pos]+q); } if(a[pos]-q>=0) { vis[l][num+a[pos]-q]=true;//printf("%d ",num+a[pos]-q); } return ; } if(a[pos]+q<10) dfs(pos+1,num+a[pos]+q,q); if(a[pos]-q>=0) dfs(pos+1,num+a[pos]-q,q); } int main(){ #ifdef shuaishuai freopen("C:\Users\hasee\Desktop\a.in","r",stdin); freopen("C:\Users\hasee\Desktop\b.txt","w",stdout); #endif int t,kas=1; scanf("%d",&t); while(t--){ scanf("%d ",&n); int ans=0; memset(vis,false,sizeof vis); while(n--){ scanf("%s",s); l=0; int num=getnum(); if(!vis[l][num]) ans++; else continue; vis[l][num]=true; // for(int i=0;i<l;i++)printf("%d ",a[i]);printf(" "); for(int i=1;i<10;i++){ dfs(0,0,i); } } printf("Case %d: %d ",kas,ans);kas++; } return 0; }
原文地址:https://www.cnblogs.com/MeowMeowMeow/p/7277006.html