A. Calculating Function
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output题目链接: http://codeforces.com/contest/486/problem/A
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.
Input
The single line contains the positive integer n (1?≤?n?≤?1015).
Output
Print f(n) in a single line.
Sample test(s)
input
output
input
output
-3
Note
f(4)?=??-?1?+?2?-?3?+?4?=?2
f(5)?=??-?1?+?2?-?3?+?4?-?5?=??-?3
解题思路:
给你n,求f(n) 。这是一道规律题,首先确定不能暴力求解,因为n实在太大,暴力必超时。同时也开不了那么大的数组来暴力。
提笔简单算了几个,发现f(1) = -1 , f(2) = 1, f(3) = -2, f(4) = 2, f(5) = -3, f(6) = 3··········这样规律就看出来了,两个数一组,n/2如果为偶数那么符号为正,奇数符号为负。并且如果n/2为奇数的话,我们向上取整,即为n / 2 + 1
最后,中间值什么的都开成long long。
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif LL n; while(~scanf("%lld",&n)) { LL c = n / 2; if(n % 2 != 0) { c += 1; printf("-"); } printf("%lld\n" , c); }}</map></set></list></ctime></cmath></stack></queue></bitset></vector></string></cstdio></complex></cassert></climits></cstring></numeric></iomanip></sstream></fstream></iostream></algorithm></functional>

HTML不僅是網頁的骨架,更廣泛應用於多種領域:1.在網頁開發中,HTML定義頁面結構並結合CSS和JavaScript實現豐富界面。 2.在移動應用開發中,HTML5支持離線存儲和地理定位等功能。 3.在電子郵件和新聞通訊中,HTML提升郵件的格式和多媒體效果。 4.在遊戲開發中,HTML5的CanvasAPI用於創建2D和3D遊戲。

theroottaginanhtmldocumentis.servesasthetop-levellementThateNcapsulatesAllotherContent,確保properdocumentstrumentstrumentsureandbrowserparserparsing。

文章解釋說,HTML標籤是用於定義元素的語法標記,而元素是完整的單位,包括標籤和內容。他們一起工作以構建網頁。查拉克計數:159

本文討論了Lt; Head&gt; &&lt;身體&gt; HTML中的標籤,它們對用戶體驗的影響以及SEO的影響。正確的結構增強了網站功能和搜索引擎優化。

本文討論了HTML標籤,和和關注其語義與表現用途及其對SEO和可訪問性的影響之間的差異。

文章討論了在HTML中指定字符,重點介紹了UTF-8。主要問題:確保正確顯示文本,防止亂七八糟的字符,並增強SEO和可訪問性。

本文討論了用於構建和造型Web內容的各種HTML格式標籤,強調了它們對文本外觀的影響以及語義標籤對可訪問性和SEO的重要性。

本文討論了HTML的“ ID”和“類”屬性之間的差異,重點是它們的獨特性,目的,CSS語法和特異性。它解釋了它們的使用如何影響網頁樣式和功能,並為


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

禪工作室 13.0.1
強大的PHP整合開發環境

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

記事本++7.3.1
好用且免費的程式碼編輯器