E - Number Sequence(第二季水)
Description
Input
Output
Sample Input
2
8
3
Sample Output
2
2 这道题不打表会超时 ,以下 超时代码
#include<iostream>
#include<cmath>
using namespace std;
void f(int n)
{
int p=,j=,t;
bool flag;
while(){
flag=false;
for(j=;j<=p;j++){
int i;
for(i=;;i++){
t=pow((double),i);
if(j/t==){
n-=i;
break;
}
}
if(n<=){
int k=i+n;
flag=true;
n=j%(int)(pow((double),i-k+))/pow((double),i-k);
break;
}
}
if(flag==true)break;
p++;
}
cout<<n<<endl;
}
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
f(n);
}
//system("pause");
return ;
}
打表后!!!这个代码不好理解
#include<iostream>
#include<cmath>
using namespace std;
unsigned int a[],s[];
void f()
{
int i;
a[]=;
s[]=;
for(i=;i<;i++)
{
a[i]=a[i-]+(int)log10((double)i)+; //记录1至s[i]个数字的位数和
s[i]=s[i-]+a[i]; //一位 记录 1至s[i]个数字
}
}
int main()
{
int t;
int n;
int i;
cin>>t;
f();
while(t--)
{
cin>>n;
i=;
while(s[i]<n) i++;
int pos=n-s[i-];
int tmp=;
for(i=;tmp<pos;i++) //第n个数字在s[i-1]这个数据组中
{
tmp+=(int)log10((double)i)+;
}
int k=tmp-pos; //数字i从低位数的第k+1位
cout<<(i-)/(int)pow(10.0,k)%<<endl;
}
return ;
}
E - Number Sequence(第二季水)的更多相关文章
- F - The Fun Number System(第二季水)
Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...
- D - Counterfeit Dollar(第二季水)
Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...
- I - Long Distance Racing(第二季水)
Description Bessie is training for her next race by running on a path that includes hills so that sh ...
- Y - Design T-Shirt(第二季水)
Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...
- N - Robot Motion(第二季水)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- B - Maya Calendar(第二季水)
Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- R - 一只小蜜蜂...(第二季水)
Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. ...
- G - Reduced ID Numbers(第二季水)
Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...
随机推荐
- UIView的常用方法
bringSubviewToFront: 把指定的子视图移动到顶层 - (void)bringSubviewToFront:(UIView *)view 参数 view 需要移到顶层的视图 conve ...
- VLD 1.0 ReadMe翻译尝试
近期想学习下VLD的实现,打算从最简单的V1.0版本看起.以下是V1.0版本自己尝试翻译下,最新的2.x版本似乎强大了很多. 简介 Visual C++提供了内置的内存检测机制,但其充其量只满足了最小 ...
- 用ant重新编译jdk加入调试信息
(文章后面提供了ant和build.xml打包之后的build.zip下载,解压build.zip,然后将apache-ant-1.9.2-bin.zip解压即完成了ant安装,也可到http://a ...
- phpexcel导入excel文件报the filename xxx is not recognised as an OLE file错误。
工作中频繁会用phpexcel类导入excel文件的数据到数据库,目前常用的excel文件格式有:xls.csv.xlsx. 刚开始,针对xls文件,使用如下程序,能正常运行: $objReader ...
- org.quartz.impl.jdbcjobstore.LockException
说明:在使用Tomcat6.0.32+Spring3.05+Quartz1.8.6+Mysql5.5.9 此项目在我本机上没有问题,当我把mysql 脚本导入到服务器上,将数据源配置修改为服务器对应的 ...
- Socket也有专门的Unicode版本
https://www.chilkatsoft.com/refdoc/wcppCkSocketWRef.html https://www.chilkatsoft.com/refdoc/vcCkSock ...
- ant的入门 配置与安装
最近需要用ant来生成文件,java类.我才开始了解了这个工具.仔细看了一下,感觉这个小工具的强大功能. 博主也是初学者,在网上收集了资料,尝试了配置:感觉有些高手写得不错变引用之. 配置如下: 以上 ...
- cf478C Table Decorations
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 一、crond简介
crond 是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务 工具,并且会自动启动crond进程,cro ...
- UIScollView Touch事件
customScrollView.h #import <UIKit/UIKit.h> @interface customScrollView : UIScrollView @end cus ...