HDU 2011 (水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2011
题目大意:给你 m 个数,对于每个数,求前 n 项和,数列:1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ...
解题思路:
很水,搞一下就出来了
代码:
#include<iostream>
#include<cmath>
#include<iomanip>
//#include<algorithm>
double s[];
using namespace std;
int main()
{
int p = ;
double sum = ;
for(int i = ; i <= ; i ++)
{
s[i] = s[i - ] + / (pow(-, i - ) * (p++));
}
int x;
int m;
while(cin >> m)
{
for(int i = ; i < m; i ++)
{
cin >> x;
cout << fixed << setprecision() << s[x] << endl;
}
}
}
学到一个三目运算符:
1.a>b?a:c>d?c: d 等价于 a>b?a:(c>d?c:d) 从右往左
2. if(a>b) max=a;
2 else max=b;
可用条件表达式写为 max=(a>b)?a:b;
HDU 2011 (水)的更多相关文章
- HDU-1042-N!(Java大法好 && HDU大数水题)
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Subm ...
- hdu 4464 水
http://acm.hdu.edu.cn/showproblem.php?pid=4464 现场赛总会有水题,这就是最水的一道,预计也就是能当高校的上机题,保研用,呵呵~~~ #include &l ...
- HDU 2011 多项式求和
http://acm.hdu.edu.cn/showproblem.php?pid=2011 Problem Description 多项式的描述如下:1 - 1/2 + 1/3 - 1/4 + 1/ ...
- HDU 5391 水题。
E - 5 Time Limit:1500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 1544 水题
水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...
- hdu 3357 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...
- hdu 5007 水 弦
http://acm.hdu.edu.cn/showproblem.php?pid=5007 纯粹的联系String的substr 什么时候substr拦截比写短话 string te; int n; ...
- Tickets HDU - 1260 水DP
HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1 ...
- HDU排序水题
1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...
随机推荐
- Springboot整合https原来这么简单
1 简介 HTTP是不安全的,我们需要给它套上SSL,让它变成HTTPS.本文章将用实例介绍Springboot整合HTTPS. 2 密码学基础 要谈https就要谈Security,自然就要谈安全: ...
- synchronized 的实现原理
加不加 synchronized 有什么区别? synchronized 作为悲观锁,锁住了什么? synchronized 代码块怎么用 前面 3 篇文章讲了 synchronized 的同步方法和 ...
- StringRedisTemplate的常用操作
stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);//向r ...
- Qt 正则表达式检查 IP 格式
KillerSmath 2018年6月29日 下午10:41 @Pranit-Patil Hi there. Like @jonB says above, you should to replace\ ...
- [Qt] 文本文件读写, 摘自官方文档
Reading Files Directly The following example reads a text file line by line: QFile file("in.txt ...
- Flutter自己实现一个ProgressHUD
用惯了iOS的SVProgressHUD,但是在flutter pub上的并没有找到类似的实现,于是自己实现一个 主要实现四个基本功能 Loading显示 成功显示 错误显示 进度显示:环形进度条和文 ...
- python操作ftp文件
from ftplib import FTP ftp = FTP('ftp.abc.com') ftp.login(user='username', passwd='********') ftp.cw ...
- 算法竞赛进阶指南--hamilton路径
// hamilton路径 int f[1 << 20][20]; int hamilton(int n, int weight[20][20]) { memset(f, 0x3f, si ...
- 数学--数论--随机算法--Pollard Rho 大数分解算法 (带输出版本)
RhoPollard Rho是一个著名的大数质因数分解算法,它的实现基于一个神奇的算法:MillerRabinMillerRabin素数测试. 操作流程 首先,我们先用MillerRabinMille ...
- 数据结构--栈(附上STL栈)
定义: 栈是一种只能在某一端插入和删除数据的特殊线性表.他按照先进先出的原则存储数据,先进的数据被压入栈底,最后进入的数据在栈顶,需要读数据的时候从栈顶开始弹出数据(最后被压入栈的,最先弹出).因此栈 ...