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 ...
随机推荐
- kafka相关术语名词
Topic:标签名,一个消息队列的名称 Producer:生产者,发布消息 Consumer:消费者,订阅发布消息,进行处理的存在 Broker:kafka集群,有一个.多个Topic Partiti ...
- git工具上传项目到码云
首先,你需要在本地安装git客户端,此处简单易懂,略过然后,在本地建好文件夹,以本人为例,我的路径为 E:\git_project,此时需要通过鼠标右键选择:git bush here 如图所示然后会 ...
- 20199308《Linux内核原理与分析》第十二周作业
一.实验简介 竞态条件是指多个线程同时访问或者操作同一块数据,运行的结果依赖于不同线程访问数据的顺序.如果一个拥有root权限的程序存在竞态条件漏洞的话,攻击者可以通过运行一个平行线程与漏洞程序竞争, ...
- Ubuntu 安装 Qt, 安装辅助软件
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev sudo apt-get install gcc g++ sudo apt-get inst ...
- Linux磁盘修复命令----fsck
使用fsck命令修复磁盘时 一定要进入单用户模式去修复 语 法fsck.ext4[必要参数][选择参数][设备代号] 功 能fsck.ext4 命令: 针对ext4型文件系统进行检测 参数 -a 非 ...
- 一份中外结合的 Machine Learning 自学计划
看了Siraj Raval的3个月学习机器学习计划的视频,感觉非常好,地址:https://www.youtube.com/watch?v=Cr6VqTRO1v0 结合一些我们学习中的经验得出一份Hy ...
- CodeForces-1058B B. Vasya and Cornfield
这题,我真的不知道题解是啥,自己看代码吧. #include<iostream> using namespace std; int main() { int n, d,m,i,x,y; c ...
- Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)
Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the L ...
- python(For 循环语句)
一.For循环 Python for 循环可以遍历任何序列的项目,如一个列表或者一个字符串或者字典等. 语法模式:for var in sequence: (1)从某个集合(列表等)里顺次取值 #遍历 ...
- golang之method
method Go does not have classes. However, you can define methods on types. package main import ( &qu ...