Codeforces Round #277 (Div. 2)---A. Calculating Function (规律)
1 second
256 megabytes
standard input
standard output
For a positive integer n let's define a function f:
f(n) = - 1 + 2 - 3 + .. + ( - 1)nn
Your task is to calculate f(n) for a given integer n.
The single line contains the positive integer n (1 ≤ n ≤ 1015).
Print f(n) in a single line.
4
2
5
-3
f(4) = - 1 + 2 - 3 + 4 = 2
f(5) = - 1 + 2 - 3 + 4 - 5 = - 3
解题思路:大水题一枚。直接找规律。n%2==0时,f = n/2; 否则,f = -(n+1)/2.
AC代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int main()
{
// #ifdef sxk
// freopen("in.txt","r",stdin);
// #endif
long long n;
while(scanf("%lld",&n)!=EOF)
{
if(n & 1) printf("%lld\n", -(n+1)/2);
else printf("%lld\n", n/2);
}
return 0;
}
Codeforces Round #277 (Div. 2)---A. Calculating Function (规律)的更多相关文章
- Codeforces Round #277 (Div. 2) A. Calculating Function 水题
A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...
- Codeforces Round #277 (Div. 2)A. Calculating Function 水
A. Calculating Function For a positive integer n let's define a function f: f(n) = - 1 + 2 - 3 + ...
- codeforces水题100道 第十题 Codeforces Round #277 (Div. 2) A. Calculating Function (math)
题目链接:www.codeforces.com/problemset/problem/486/A题意:求表达式f(n)的值.(f(n)的表述见题目)C++代码: #include <iostre ...
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- Codeforces Round #277 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...
- Codeforces Round #277 (Div. 2) A B C 水 模拟 贪心
A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 套题 Codeforces Round #277 (Div. 2)
A. Calculating Function 水题,分奇数偶数处理一下就好了 #include<stdio.h> #include<iostream> using names ...
随机推荐
- 算法-基数排序(radix sort)
本文由@呆代待殆原创,转载请注明出处. 简介:这个排序是原来用在卡片排序机上的一个算法,一般用来比较具有多对关键字域的记录,如日期(年月日),通过基数排序我们会依次对年月日这三个关键字进行排序,只要对 ...
- 【枚举】bzoj1643 [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
显然<=n的平方数只有sqrt(n)个,三重循环枚举三块草坪,再减一下验证最后一块是不是平方数.O(n*sqrt(n)). #include<cstdio> #include< ...
- 【权值分块】bzoj1503 [NOI2004]郁闷的出纳员
权值分块,离散化非常蛋疼,只能离散化搞…… 需要支持操作:删除<=某个值得所有权值==打标记 O(sqrt(n)) 码长和我的平衡树差不多……速度快3倍左右. #include<cstdi ...
- 1.8(学习笔记)监听器(Listener)
一.监听器简介 监听器是web容器对某一些对象的监听,当某些对象发生创建.修改.删除的动作时, web容器会自动调用对应的监听器中的方法. 例如A是监听器,B是被监听对象,A的监听任务是B回家时来开门 ...
- Problem I: 零起点学算法30——输出四位完全平方数
#include<stdio.h> int main() { int a,b,c,d,s,i; ;i<;i++){ s=i*i; a=s/; b=s%/; c=s%/; d=s%; ...
- 求同余方程x^A=B(mod m)的解个数(原根与指标)
求方程:的解个数 分析:设,那么上述方程解的个数就与同余方程组:的解等价. 设同于方程的解分别是:,那么原方程的解的个数就是 所以现在的关键问题是求方程:的解个数. 这个方程我们需要分3类讨论: 第一 ...
- 使用ab.exe监测100个并发/100次请求情况下同步/异步访问数据库的性能差异
ab.exe介绍 ab.exe是apache server的一个组件,用于监测并发请求,并显示监测数据 具体使用及下载地址请参考:http://www.cnblogs.com/gossip/p/439 ...
- GLEW扩展库【转】
http://blog.sina.com.cn/s/blog_4aff14d50100ydsy.html 一.关于GLEW扩展库: GLEW是一个跨平台的C++扩展库,基于OpenGL图形接口.使用O ...
- scrapy-splash抓取动态数据例子十二
一.介绍 本例子用scrapy-splash通过搜狗搜索引擎,输入给定关键字抓取资讯信息. 给定关键字:数字:融合:电视 抓取信息内如下: 1.资讯标题 2.资讯链接 3.资讯时间 4.资讯来源 二. ...
- nginx监听相同端口,根据域名请求不同的server
nginx监听相同端口,根据域名请求不同的server 学习了:https://blog.csdn.net/liaosiqian/article/details/54861270 注意其中用的是rew ...