2019 年百度之星·程序设计大赛 - 初赛一 1005 Seq(数学规律)
2024-09-03 16:36:39
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=861&pid=1005
Sample Input
Sample Output
这题第一反应打表,先计算,后查询输出,后来注意到数据太大,行不通
索性把打好的表输出来找规律,果然有规律可循
奇数和偶数有不同的规律,但周期都是3
大家可以把下面的代码跑一下,分别输出1到30之间的奇数和偶数项的结果,试着自己找一找规律
代码如下:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const double PI=acos(-);
const int maxn=1e5+;
using namespace std; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
LL n;
scanf("%lld",&n);
if(n&==)//奇数项
{
LL num,a,b;
int p,q;
num=(n+)/;//算一下是第几个奇数
p=;
q=;
a=num/;
b=num%;
if(b==)
printf("%lld\n",p+*a);
else if(b==)
printf("%lld\n",q+a);
else if(b==)
printf("%lld\n",q+a-);
}
else//偶数项
{
LL num,a,b;
num=n/;//算一下是第几个偶数
if(n==) //把2当做了特殊项,便于以后计算
printf("1\n");
else
{
a=(num-)/;
b=(num-)%;
if(b==)
printf("%lld\n",n-);
else
printf("%lld\n",n/);
}
}
}
return ;
}
最新文章
- 转载文档:Storm实战常见问题及解决方案
- URLDecoder解析url编码
- OpenCV2马拉松第22圈——Hough变换直线检測原理与实现
- C读写配置文件
- C语言基础学习学习前的准备-2
- grok 官方文档
- C#设计模式之二十二访问者模式(Visitor Pattern)【行为型】
- Spring 的IOC和AOP总结
- <;算法图解>;读书笔记:第2章 选择排序
- 边缘检测之Canny
- Vultr新用户充值优惠 – 最多充值100美元送100美元
- 第86节:Java中的JQuery基础
- [Linux 性能调优] 网卡中断与CPU的绑定问题
- DL_1_week1_概论
- Easyui和IE浏览器的兼容问题
- 十三、MVC的WEB框架(Structs2)
- wampserver的配置教程
- runOnUiThread更新主线程
- Codeforces 862C - Mahmoud and Ehab and the xor
- eclipse从svn导入maven项目变成普通项目解决办法