85-有趣的数

内存限制:64MB 时间限制:3000ms 特判: No

通过数:8 提交数:12 难度:2

题目描述:

把分数按下面的办法排成一个数表。

1/1 1/2 1/3 1/4…

2/1 2/2 2/3…

3/1 3/2 …

4/1…

我们以z字型方法给上表的每项编号。特定方法:第一项是1/1,然后是1/2、2/1、3/1、2/2、1/3、1/4、2/3……。编程输入项号N(1<=N<=100000),输出表中第N项。

输入描述:

第一行有一个整数m(0<m<=10),表示有m组测试数据;

随后有m行,每行有一个整数N;

输出描述:

输出表中第N项

样例输入:

复制

4

3

14

7

12345

样例输出:

2/1

2/4

1/4

59/99

思路

将题目描述的数表输出出来,进行找规律,可以发现有如下规律:在一段连续的区间内,分子和分母加起来是固定的值。
假设分子分母之和为N,当N是奇数时,分子是从小到大(从1−&gt;N−11-&gt;N-11−>N−1);当N是偶数时,分子从大到小(从N−1−&gt;1N-1-&gt;1N−1−>1)
对这个规律进行打表即可

不知道为什么,数组大小开到1e5会出错,明明数据范围是1e5

AC代码

/*
* @Author: WZY
* @School: HPU
* @Date: 2018-10-22 17:12:37
* @Last Modified by: WZY
* @Last Modified time: 2018-10-22 22:48:31
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#include <time.h>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
#define bug cout<<"-------------"<<endl
#define debug(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<"\n"
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int a[maxn],b[maxn];
int k;
inline void init()
{
k=0;
for(int i=1;i<1000;i++)
{
if(i&1)
{
for(int j=1;j<i;j++)
{
a[++k]=j,b[k]=i-j;
if(k>=maxn)
return;
}
}
else
{
for(int j=i-1;j>=1;j--)
{
a[++k]=j,b[k]=i-j;
if(k>=maxn)
return;
}
}
}
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
double _begin_time = clock();
#endif
init();
int t;
// for(int i=1;i<1000;i++)
// {
// debug(i);
// debug(a[i]);
// debug(b[i]);
// }
cin>>t;
while(t--)
{
int n;
cin>>n;
cout<<a[n]<<"/"<<b[n]<<endl;
}
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %lf ms.", _end_time - _begin_time);
#endif
return 0;
}

NYOJ 85:有趣的数(打表,规律)的更多相关文章

  1. nyoj 85 有趣的数

    点击打开链接 有趣的数 时间限制:3000 ms  |  内存限制:65535 KB 难度: 描述 把分数按下面的办法排成一个数表. 1/1 1/2 1/3 1/4..... 2/1 2/2 2/3. ...

  2. NYOJ-85 有趣的数 AC 分类: NYOJ 2014-01-17 21:42 240人阅读 评论(0) 收藏

    这道题目就是,找规律,小学奥数,找规律不难吧, #include<stdio.h> int sc(int x); int main(){ int n=0; int num,cs,k; sc ...

  3. nyoj_85_有趣的数_201312122130

    有趣的数 时间限制:3000 ms  |           内存限制:65535 KB 难度:2   描述 把分数按下面的办法排成一个数表. 1/1 1/2 1/3 1/4..... 2/1 2/2 ...

  4. Oracle 查询库中所有表名、字段名、字段名说明,查询表的数据条数、表名、中文表名、

    查询所有表名:select t.table_name from user_tables t;查询所有字段名:select t.column_name from user_col_comments t; ...

  5. CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)

    问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...

  6. P2022 有趣的数

    P2022 有趣的数 题目描述 让我们来考虑1到N的正整数集合.让我们把集合中的元素按照字典序排列,例如当N=11时,其顺序应该为:1,10,11,2,3,4,5,6,7,8,9. 定义K在N个数中的 ...

  7. CCF软考---《有趣的数》

    脑子一热报了CCF的软测..但是又觉得好像并没有什么卵用,就当为蓝桥杯预热然后顺便去软件学院玩一玩吧,遇到一个有意思的题: time limits : 1s 问题描述 我们把一个数称为有趣的,当且仅当 ...

  8. CCF系列之有趣的数(201312-4)

    题目链接: http://115.28.138.223:81/view.page?opid=4 试题名称: 有趣的数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 我们把一个 ...

  9. CSP201312-4 有趣的数【dp】

    问题描述 试题编号: 201312-4 试题名称: 有趣的数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, ...

  10. ccf 201312-04 有趣的数(组合数学)

    问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...

随机推荐

  1. 加号变空格问题 url参数 post get 请求发送

    问题:加号后台接收变空格问题 结论: 1.任何get拼接的请求 参数key value 需要编码后在拼接 2.get请求避免做数据提交,用post提交.jq,axios的post提交默认编码了不会有问 ...

  2. python常用

    列出当前目录 import os: print os.getcwd() python load .mat variable a import scipy.io as sp tmp=sp.loadmat ...

  3. Win10系列:VC++绘制文本

    20.7.2小节介绍了如何使用Direct2D在应用窗口中绘制图片,本小节将基于20.7.2小节的项目进一步介绍如何实现文本的绘制.打开D2DBasicAnimation.h头文件,并在D2DBasi ...

  4. java倒计时使用ScheduledExecutor实现,使用两个线程,以秒为单位

    public class Countdown2 { private volatile int lin; private int curSec; public Countdown2(int lin) t ...

  5. Unity中Text中首行缩进两个字符和换行的代码

    1.首行缩进两个字符 txt.text=“\u3000\u3000” + str: 2.首行缩进两个字符 将输入法换成全角的,在Text属性面板中添加空格即可. 3.换行    “\n” 补充 Uni ...

  6. bzoj1666

    题解: 简单模拟 按照题目意思来就可以了 代码: #include<bits/stdc++.h> using namespace std; int n,ans; int main() { ...

  7. netcore 2.0 部署 到iis

    .net Core2.0应用程序发布window服务器报错容易错过的配置. 1.应用程序发布. 2.IIS上新建网站. 3.应用程序池选择无托管代码. 4.服务器上安装DotNetCore.1.0.2 ...

  8. 7 Serial Configuration 理解 (一)

    reference :  ug470- 7 series config.pdf 7系列器件有5种配置接口,每种配置接口对应一种或者多种配置模式和总线位宽.配置时序相对于引脚的CCLK,即使在内部产生C ...

  9. org.quartz-scheduler 动态添加自动任务

    1.添加pom.xml <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId> ...

  10. ClickOnce 和管理员权限

    有些程序需要管理员权限需要运行,同时又想用ClickOnce进行发布,这时候就麻烦了,两者是互斥的. 解决方案是,去掉管理员权限的要求,可以进行发布. 程序启动的时候,加载程序员权限的请求. 代码如下 ...