fzu 1675 The Seventy-seven Problem

给你长度为 10^5~10^6长度,由数字组成的串 其中有4位不见了 补全该串 使得在该串能整除 77的同时 尽可能大
// 先计算出每个 n*10^m 模 77 的循环节 n=0,1,2..,9
// 然求出串的每位 mod 77 累加 抹黑的4为另外处理

#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <math.h> #include <stdio.h> #include <string.h> using namespace std; #define maxm 100010 #define maxn 1000110 int rc[10][10]; int num[10]; void calculate(int n){ int vi[100]={0}; int m=n; int ct=0; rc[m][ct++]=m; vi[n]=true; while(1){ n=n*10; n=n%77; if(vi[n]) break; vi[n]=true; rc[m][ct++]=n; // printf("%d\n",n); } num[m]=ct; } char str[maxn]; int main() { int i,j,k,l; int d[11]={0,9,8,7,6,5,4,3,2,1,0}; int a[5]; for(i=1;i<=9;i++) calculate(i); num[0]=1; // for(i=1;i<=9;printf("\n"),i++) // for(j=0;j<num[i];j++) // printf("%d ",rc[i][j]); int tp; // printf("%d\n",11167%77); while(scanf("%s",str)!=EOF){ int len=strlen(str); tp=j=0; for(i=0;i<len;i++){ if(str[len-i-1]!='x'){ k=str[len-i-1]-'0'; tp+=rc[k][i%num[k]]; }else{ a[++j]=i; // printf("%d ",i); } } // printf("%d\n",tp); int lin; int flag=1; for(i=1;i<=10;i++) { for(j=1;j<=10;j++) { for(k=1;k<=10;k++){ for(l=1;l<=10;l++){ lin=tp+rc[d[l]][a[1]%num[d[l]]]; lin=lin+rc[d[k]][a[2]%num[d[k]]]; lin=lin+rc[d[j]][a[3]%num[d[j]]]; lin=lin+rc[d[i]][a[4]%num[d[i]]]; if(lin%77==0) {flag=0;break;} } if(!flag) break; } if(!flag) break; } if(!flag) break; } str[len-a[1]-1]='0'+d[l]; str[len-a[2]-1]='0'+d[k]; str[len-a[3]-1]='0'+d[j]; str[len-a[4]-1]='0'+d[i]; printf("%s\n",str); } return 0; }

 

转载于:https://www.cnblogs.com/372465774y/p/3210051.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值