现在的位置: 首页 > 综合 > 正文

HDOJ 1597 不知道属于什么的水题

2017年11月23日 ⁄ 综合 ⁄ 共 430字 ⁄ 字号 评论关闭

假设:
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........

那么你能告诉我在S串中的第N个数字是多少吗?


#include<iostream>
using namespace std;
// 1+2+3+4+5...+8=36
int main(){
	int K,n;
	cin>>K;
	while(K--){
		cin>>n;
		int ans=n;
		int acu=0,tmp=1;
		while(acu+tmp<ans){
			acu+=tmp;
			tmp++;
		}
		ans=ans-acu;		
		ans=(ans-1)%9+1;
		cout<<ans<<endl;
	}
	return 0;
}

抱歉!评论已关闭.