为防止广告,目前nocow只有登录用户能够创建新页面。如要创建页面请先登录/注册(新用户需要等待1个小时才能正常使用该功能)。

Sgu/108

来自NOCOW
< Sgu
跳转到: 导航, 搜索

[编辑] Pascal

本菜一不小心发现了一个规律,在此显摆显摆~
首先,打出满足200以下的表,以等差数列的思维观察,显然发现,差为11的占多数,因而,在凡是不是11
为差的,另起一行,然后删除前5行,寻找规律~
Program Self_numbers_2;
Const
	inp='input.txt';
	oup='output.txt';
	maxn=977787+21;
Var
	i,l,n,k:longint;
	s:array[0..maxn] of longint;
Begin
	assign(input,inp); reset(input);
	assign(output,oup); rewrite(output);
	read(n);
	for i:=1 to 4 do s[i]:=i shl 1-1;
	for i:=1 to 10 do s[i+4]:=(i-1)*11+9;
	s[0]:=15;
	s[15]:=110;
	for l:=2 to 99999 do
		begin
			if (l mod 10000=1) or (l mod 10000=0) then k:=6
			else if (l mod 1000=1) or (l mod 1000=0) then k:=7
			else if (l mod 100=1) or (l mod 100=0) then k:=8
			else if (l mod 10=1) or (l mod 10=0) then k:=9
			else k:=10;
			for i:=2 to k do
				begin
					inc(s[0]); s[s[0]]:=s[s[0]-1]+11;
				end;
			if l mod 10000=0 then k:=54
			else if l mod 1000=0 then k:=41
			else if l mod 100=0 then k:=28
			else if l mod 10=0 then k:=15
			else k:=2;
			inc(s[0]); s[s[0]]:=s[s[0]-1]+k; if s[s[0]]>=n then break;
		end;
	for i:=1 to 4 do
		begin
			inc(s[0]); s[s[0]]:=s[s[0]-1]+11;
		end;
	readln(k); while s[s[0]]>n do dec(s[0]);
	writeln(s[0]);
	read(n); write(s[n]);
	for i:=2 to k do
		begin
			read(n);
			write(' ',s[n]);
		end;
	close(output); close(input);
End.

[编辑] Cpp

注意,s可以有重复(我被卡在这了) 下面是朴素

#include<iostream>
#include<algorithm>
using namespace std;
struct Data
{
	int q,ord;
}s[5005];
bool cmp1(Data a,Data b){return a.q<b.q;}
bool cmp2(Data a,Data b){return a.ord<b.ord;}
int p,tot,add,wss[15],n,k;
bool vis[150];
const int MOD=140;
void dfs(int w,int he,bool up)
{
	if(w==0)
	{
		if(he!=0)
		{
			if(!vis[he%MOD])
			{
				tot++;
				while(tot==s[p].q){s[p].q=he;p++;}//防止重复
			}
			vis[he%MOD]=false;
			vis[(he+add)%MOD]=true;
		}
		++add;
		return ;
	}
	int top=9;
	if(up) top=wss[w];
	for(int i=0;i<=top;i++)	dfs(w-1,he*10+i,up&&i==top);
	add-=9;
	return ;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=k;i++) {cin>>s[i].q;s[i].ord=i;}
	sort(s+1,s+k+1,cmp1);p=1;
	for(int i=1;i<=8;i++) {wss[i]=n%10;n/=10;}
	dfs(9,0,true);
	cout<<tot<<endl;
	sort(s+1,s+k+1,cmp2);
	cout<<s[1].q;
	for(int i=2;i<=k;i++) cout<<" "<<s[i].q;
	return 0;
}
个人工具