Source
source=%e6%b9%96%e5%8d%97%e7%9c%81%e7%ac%ac%e4%b8%83%e5%b1%8a%e5%a4%a7%e5%ad%a6%e7%94%9f%e8%ae%a1%e7%ae%97%e6% 9c%ba%e7%a8%8b%e5%ba%8f%e8%ae%be%e8%ae%a1%e7%ab%9e%e8%b5%9b "style=" text-decoration:none; Color:rgb (55,119,188) > Hunan Seventh session of computer Program design contest for university students
A simple simulation problem: to simulate the occurrence of the situation, mainly to introduce a rule in the position of the boundary, the next count of the position is 2*n-2. (I don't know how it was introduced.)
This makes it possible to calculate the position of each number next to the count, and infer directly.
#include <cstdio> #include <cstring>bool judge (int n)//infer function, infer whether it contains 7, or a multiple of 7 { if (!) n% 7)) return true; while (n) { if (n% = = 7) return true; n/=; } return false;} int main () { int n,m,k,i; while (scanf ("%d%d%d", &n,&m,&k) &&n&&m&&k) { int count=0; for (i=7;; i++) { if (judge (i)) { int x=i% (2*n-2);//derived from the initial number if (x==0) x=2*n-2; if (X==m | | (X>=n && 2*n-x==m)) Conform to the situation of test instructions count++; if (count==k) break ; } } printf ("%d\n", I); } return 0;}
Also see others have a way of thinking, directly find the law, according to the rule of violence solution.
Divided into two parts to consider, the boundary situation is directly 2*n-2, the intermediate interval is two number cycle change.
#include <cstdio> #include <iostream>using namespace std;bool is7 (int n)//inferred {if (! ( n% 7)) return true; while (n) {if (n% = = 7) return true; n/= 10; } return false;} int main () {int n, m, K; while (scanf ("%d%d", &n, &m, &k)!=eof && n+m+k) {int cnt = 0, period = 2 * n-2; if (n = = m | | m = = 1)//Boundary condition {for (int i = m;; i + = period) if (IS7 (i)) { cnt++; if (cnt = = k) {printf ("%d\n", I); Break }}} else {int next = 2-m; for (int i = m;; Swap (Next, I))//Middle Condition {next + = period; if (IS7 (i)) {cnt++; if (cnt = = k) {printf ("%d\n",i); Break }}}}} return 0;}
A different way of thinking. Direct simulation, according to the first order, after the reverse of the simulation;
#include <cstdio> #include <cstring>bool judge (int n)//Infer {if (! n% 7)) return true; while (n) {if (n% = = 7) return true; n/= 10; } return false;} int main () {int n,m,k,i; while (scanf ("%d%d%d", &n,&m,&k) &&n&&m&&k) {int pos=0,count=0,flag=0; for (i=1;i<=n;i++)//sequential processing {pos++; if (i==m) {if (Judge (POS)) count++; if (count==k)//search results for {printf ("%d\n", POS); Break }} if (I==n) {i=n-1;//in reverse processing for (; i>=1;i--) {pos++; if (i==m) {if (Judge (POS)) count++; if (count==k) { flag=1; printf ("%d\n", POS); Break }}} if (flag) break; i=1;//back to Order}}} return 0;}