首页 > 其他分享 >Codeforces Round 863 (Div. 3) E题

Codeforces Round 863 (Div. 3) E题

时间:2023-04-05 19:58:32浏览次数:46  
标签:10 int res 863 Codeforces mid ans Div dp

题目地址

题意:定义数组a包含所有不含数字4的正整数,给出一个n,要求求出数组a中第n个数

Solution

数位dp+二分,求出[1,mid]中不含数字4的正整数个数,不过因为有可能mid包含4,但是由于贡献是一样的,可以直接把4都变成3,最后处理一下即可

int dp[20];
int a[20];
void init()
{
	dp[0]=1;
	for(int i=1;i<20;i++)
	{
		dp[i]=dp[i-1]*9;
	}
}

int dfs(int x)
{
	int len=0;
	int temp=x;
	while(temp>0)
	{
		a[++len]=temp%10;
		temp/=10;
	}
	int res=0;
	for(int i=len;i>=1;i--)
	{
		if(a[i]<4)res+=a[i]*dp[i-1];
		else if(a[i]>=4)res+=(a[i]-1)*dp[i-1];
		
	}
	return res;
}
int ans[30];

void solve()
{
	int n;cin>>n;
	int l=1,r=1e18;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(dfs(mid)<n)l=mid+1;
		else r=mid;
	}
	int t=0;
	while(l>0)
	{
		int x=l%10;
		if(x!=4)ans[++t]=x;
		else ans[++t]=3;
		l/=10;
	}
	for(int i=t;i>=1;i--)cout<<ans[i];
	cout<<"\n";
	
}

标签:10,int,res,863,Codeforces,mid,ans,Div,dp
From: https://www.cnblogs.com/HikariFears/p/17290702.html

相关文章

  • Codeforces Round 863 (Div. 3)
    A.InsertDigit放在第一个比他小的数前面#include<bits/stdc++.h>usingnamespacestd;voidsolve(){intn,d;cin>>n>>d;strings;cin>>s;for(chari:s){if(d>i-'0')cout<<d,d......
  • Codeforces Round 640 (Div. 4) ABCDEFG
    https://codeforces.com/contest/1352不知道怎么的复制过来的代码容易歪,观看效果可能不大好。这场古早div4,大题极其友好,除了E卡空间卡到我爆炸,别的都体验感极好。A.SumofRoundNumbers#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpai......
  • Codeforces Round 863 (Div. 3) A-C 赛后思路复盘
    A(思维)思路:观察样例可知数越大放在前面越优。遍历字符串,判断当前位置的数字和要插入的数字的关系,如果要插入的数大于当前数,那么就插入到当前数的前面。string里有一个insert函数,可以把指定字符串插入到指定下标之前。在原串下标为pos的字符前插入字符串strbasic_string&insert......
  • cf-div.3-863d
    题目链接:https://codeforces.com/contest/1811/problem/D思维题,昨天被E题搞太久了,这题认真想的话应该可以出的。思路:不断循环,判断x和y是否在合法区间内。代码:#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+10;longlongfib[70];voidsolve(){int......
  • codeforces round 862
    A.和洛谷上的删数思路一致,后者是找峰顶,这个是找谷底从前到后枚举每一位与要添加的数比大小,如果要添加的数<=该位的数,就继续枚举,否则就将这个数添加在其前面B.需要移动的步数=两个点所在的层数之差的绝对值,只要计算出所在层数就可以一开始没想明白怎么算这个层数,先把每个......
  • Codeforces Round 861 (Div. 2)
    Preface这场感觉都是一个礼拜前补题打的了,但由于上周末事情比较多都没来得及写题解因此可能题意都记得不是很清楚了,就简略地谈一谈吧A.LuckyNumbers不难想到直接暴力从左端点枚举到右端点并对每个数进行暴力判断一个很naive的结论就是当答案为\(9\)时直接输出即可,然后我们......
  • Codeforces Round 862 A-E
    CodeforcesRound862(Div.2)先简单写一下A-E的题解。A异或的经典性质:\(x\oplusx=0\)。B显然要把字典序最小的那个字母放到最前面。如果这个字母出现了很多次,那么应该选择最后一次出现的位置。这也很容易证明。C联立以后计算一下就行了。比赛的时候爆了一次int。......
  • Codeforces Round 717 (Div. 2) B. AGAGA XOOORRR(位运算)
    https://codeforces.com/contest/1516/problem/B题目大意:给定长度为n的数组a,问我们能不能一直选择两个相邻的元素进行异或后,删除这两个值,把异或值留下来,最后剩下>=2个数字,它们都是相同的?可以做到输出YES,不能的话输出NO。input23022423110outputYESNO题......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)-C
    参考了佬的c题题解思路,感觉很巧妙,记录一下https://zhuanlan.zhihu.com/p/618685370#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=2*100010;inta[N];voidsolve(){ intn,c,d; cin>>n>>c>>d; set<int>se......
  • Multimedia (MP3, MPEG-4, AVI, DiVX, etc.) support in Ubuntu 12.04 (Precise)
    Whydoesn’tUbuntusupportMP3‘outofthebox’?UbuntucannotincludesupportforMP3orDVDvideoplaybackorrecording.MP3formatsarepatented,andthepatentholdershavenotprovidedthenecessarylicenses.Ubuntualsoexcludesothermultimediasof......