0
点赞
收藏
分享

微信扫一扫

HDU-1597 find the nth digit(思维)

花明 2022-06-27 阅读 36

原题链接: ​​http://acm.hdu.edu.cn/showproblem.php?pid=1597​​

HDU-1597 find the nth digit(思维)_#define
测试样例

Sample Input
6
1
2
3
4
5
10
Sample Output
1
1
2
1
2
4

解题思路: 我们把每个HDU-1597 find the nth digit(思维)_c代码_02看成一组,由于长度呈等差数列增长,故我们可以第HDU-1597 find the nth digit(思维)_#define_03个数字判断是在哪个组中,知道了这个我们对每个组继续进行分析,我们发现是以1~9为一个循环,所以我们只要知道这个第HDU-1597 find the nth digit(思维)_#define_03个数字是在这个组中的哪个位置,则此题自然易解。注意思维,具体看代码。

AC代码

/*

*
*/
#include<bits/stdc++.h>//POJ不支持

#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)

using namespace std;

const int inf=0x3f3f3f3f;//无穷大。
const int maxn=1e5;//限定值。
typedef long long ll;

int k,n;
int main(){
while(cin>>k){
while(k--){
cin>>n;
int cnt=1;
while(n>cnt){
n-=cnt;
cnt++;
}
while(n>=10){
n-=9;
}
cout<<n<<endl;
}
}
return 0;
}


举报

相关推荐

0 条评论