看了看题解, 有人说本质是 F(x)=x去掉最高位+x去掉最低位,我举双手赞成
但是假设答案为ABC (C位数最低) ,F(x)=AB+BC=y
为什么推导公式是11 * B == y - C - A * pow(10,len)啊
不应该是11 * B == y - C - A * pow(10,len(B))吗?B对A应该有约束吧,百思不得其解
偷偷拿一份别人ac的代码看看是怎么个事
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 20; int ans, T; string s; int main() { cin >> T; while(T --) { ans = 0; LL a; cin >> a; for(int i = 1; i <= 9; ++ i) for(int j = 0; j <= 9; ++ j) { for(LL k = 1; k <= 1e17; k *= 10) { LL b = a - i * k - j; if(b % 11 == 0 && b >= 0 && k > b / 11) { cout<<i<<b/11<<j<<' ';cout<<i*k+j+b<<'\n'; ans ++; } } } cout << ans << endl; } return 0; } /* 5 123456789 987654321 555555555 100000000000000000 99999999999999999 */
跑的结果为
121324354 123456789 294051627 123456789 384960718 123456789 475869809 123456789 657687990 123456789 748597081 123456789 839506172 123456789 930415263 123456789 8 1806958474 987654321 2716049383 987654321 3625140292 987654321 4534231201 987654321 5443322110 987654321 7261503929 987654321 8170594838 987654321 979685747 987654321 8 1414141414 555555555 2323232323 555555555 3232323232 555555555 4141414141 555555555 550505050 555555555 5 100 100000000000000000 181818181818181819 100000000000000000 272727272727272728 100000000000000000 363636363636363637 100000000000000000 454545454545454546 100000000000000000 545454545454545455 100000000000000000 636363636363636364 100000000000000000 727272727272727273 100000000000000000 818181818181818182 100000000000000000 99090909090909091 100000000000000000 10 181818181818181818 99999999999999999 272727272727272727 99999999999999999 363636363636363636 99999999999999999 454545454545454545 99999999999999999 545454545454545454 99999999999999999 636363636363636363 99999999999999999 727272727272727272 99999999999999999 818181818181818181 99999999999999999 99090909090909090 99999999999999999 9
我承认i*k+j+b==y
但是F(121324354)=12132435+21324354=33456789肯定不等于123456789
还有10e17那个样例,明显的b是多个0组成,明显不应该啊
下面是我wawawa的代码
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 100000000 #define PII pair<int, int> #define N 200005 ll n, m,ns,mp[10][20]; void solve() { cin>>n;ns=0; ll ans=0; ll nn=n;while(nn)ns++,nn=nn/10; for(ll a=1;a<=9;a++){ for(ll c=0;c<=9;c++){ for(ll bns=0;bns<=16;bns++){ if((n-mp[a][bns]-c)<0||(n-mp[a][bns]-c)%11!=0)continue; if(bns==0){ if(a+c==n){ cout<<a<<c<<'\n';//cout<<a+c<<'\n'; ans++; } }else{ ll b=(n-mp[a][bns]-c)/11,mi=(bns==1?0:mp[1][bns-1]),mx=mp[1][bns]; if(b>=mi&&b<mx){ cout<<a<<b<<c<<'\n';//cout<<mp[a][bns]+b*11+c<<'\n'; ans++; } } } } } cout<<ans<<'\n'; } int main() { // ios::sync_with_stdio(false); // cin.tie(0); // cout.tie(0); int _ = 1; for(int i=1;i<=9;i++){ mp[i][0]=i; for(int k=1;k<=16;k++)mp[i][k]=mp[i][k-1]*10; } cin >> _; while (_--){ solve(); } return 0; }
294051627 384960718 475869809 657687990 748597081 839506172 930415263 7 1806958474 2716049383 3625140292 4534231201 5443322110 7261503929 8170594838 7 1414141414 2323232323 3232323232 4141414141 4 181818181818181819 272727272727272728 363636363636363637 454545454545454546 545454545454545455 636363636363636364 727272727272727273 818181818181818182 8 181818181818181818 272727272727272727 363636363636363636 454545454545454545 545454545454545454 636363636363636363 727272727272727272 818181818181818181 8
也有可能是我题意还是没搞懂?有无神牛帮我解解惑,,,
全部评论
(0) 回帖