(規律)cf#524-B.Margarite and the best present
https://codeforces.com/contest/1080/problem/B
規律->奇數開始每兩個數和為-1,偶數開始每兩個數和為1,處理總個數的最後一個數即可
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; typedef long long ll; int q, l, r; int main() { cin >> q; while(q--) { cin >> l >> r; int num = r - l + 1; if(num & 1) { ll ans = l & 1 ? num / 2 : -1 * num / 2; ans += r & 1 ? -r : r; cout << ans << endl; } else { ll ans = l & 1 ? num / 2 : -1 * num / 2; cout << ans << endl; } } }
相關推薦
(規律)cf#524-B.Margarite and the best present
https://codeforces.com/contest/1080/problem/B 規律->奇數開始每兩個數和為-1,偶數開始每兩個數和為1,處理總個數的最後一個數即可 #include<bits/stdc++.h> using namespa
Codeforces Round #524 (Div. 2) B. Margarite and the best present 規律題
B. Margarite and the best present time limit per test 1 second memory limit per test 256 megabytes input standard input output stand
Codeforces Round #524 (Div. 2) Margarite and the best present CodeForces - 1080B
找一下規律即可。。 #include<stdio.h> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<strin
【規律 / 等差數列求和】Margarite and the best present
題目連結 題意: 給你 [ L,R ] 一個區間,區間內的元素,奇數為負,偶數為正,求出區間內的總和。 題解: 提供兩種想法,第一種就是我自己做的,中規中矩。找出兩個最前和最後的奇數和偶數,利用等差求和求得。 #include<bits/stdc++.h> using
Margarite and the best present
put script lines turned orm %d perf recent black Little girl Margarita is a big fan of competitive programming. She especially loves prob
CF1080B Margarite and the best present
題目:Margarite and the best present 思路: 其實我們可以先列個表看看的—— a_i -1 2 -3 4 -5 6 -7 8 -9 10 sum_i -1 1 -2 2 -3 3 -4 4 -5 5
(模擬)cf#514.C.Masha and two friends
https://codeforces.com/contest/1080/problem/C 比賽的時候手寫相交判斷寫過樣例就交了,發現wa了,然後去網上抄了個板子再交還是wa。自閉 。然後比賽完看錯誤原因發現n,m沒開long long。但是還是發現板子要wa在第39個樣例,手寫
(貪心)cf#523-B.Views Matter
http://codeforces.com/contest/1061 給出x,y,呈現俯檢視和側檢視,求可以去掉多少塊是這兩個檢視不改變 5 6 3 3 3 3 3 10 首先想到排序,由大到小,在n+1個位置增加一個0的高度塊用於解第n個塊。 從第2個塊開始 對於前一個塊高度更
CodeForces 817 B.Makes And The Product(水~)
Description 給出n個正整數ai,問有多少三元組(i,j,k)滿足1≤i<j<k≤n且ai⋅aj⋅ak最小 Input 第一行一整數n表示序列長度,之後輸入n個整數ai(3≤
HD-ACM算法專攻系列(10)——大明A+B
next() http pla 分享 rgs pub system println sca 題目描述: 源碼: 需要註意的一點是輸出是最簡形式,需要去除小數的後導0,而調用stripTrailingZeros()函數後,數會以科學計數法輸出,所以需要調用toPlainS
HDU 6043 KazaQ's Socks (規律)
n-1 cnblogs sample swe 順序 裏的 this c-s close Description KazaQ wears socks everyday. At the beginning, he has nn pairs of socks numbered
Udacity資料分析(入門)-分析 A/B 測試結果
分析A/B測試結果 目錄 簡介 I - 概率 II - A/B 測試 III - 迴歸 簡介 對於這個專案,你將要了解的是電子商務網站執行的 A/B 測試的結果。你的目標是通過這個 notebook 來幫助公司弄清楚他們是否應該使用新的頁
演算法筆記 (七)PriorityQueue 實現 Huffman Tree and code
背景 在看word2vec訓練模型時發現它在優化cbow模型時採用了哈夫曼編碼,不禁勾起了以前的回憶,趁著模糊的記憶,梳理一下哈夫曼樹相關內容,在以前的文章介紹了線性表、圖等結構,這次我們正好來介紹下樹結構。
image caption筆記(三):《Show, Attend and Tell_Neural Image Caption》
一、 基本思想 文章在NIC的基礎上加入了attention機制 二、模型結構 對LSTM部分做出的改動,其餘與NIC相同。 &nbs
【hiho1878】Palindromes(規律)
題目連結 #1878 : Palindromes 時間限制:1000ms 單點時限:1000ms 記憶體限制:512MB 描述 Recently, Nvoenewr learnt palindromes in his class. A palindrome is a no
PAT乙級真題及訓練集 PAT (Basic Level) Practise (中文)1011. A+B和C
給定區間[-231, 231]內的3個整數A、B和C,請判斷A+B是否大於C。 輸入格式: 輸入第1行給出正整數T(<=10),是測試用例的個數。隨後給出T組測試用例,每組佔一行,順序給出A、B和C。整數間以空格分隔。 輸出格式: 對每組測試用例,在一行中
image caption解讀系列(二):《Show, Attend and Tell_Neural Image Caption》
一、相關工作 二、 基本思想 文章在NIC的基礎上加入了attention機制 三、模型結構 對LSTM部分做出的改動,其餘與NIC相同。 四、程式碼分析 (0)預處理 首先是把資料中長度大於2
推薦系統論文筆記(1):Hybrid Recommender Systems:Survey and Experiments
一、基本資訊 論文題目: 《Hybrid Recommender Systems:Survey and Experiments》 論文發表時間: 2002, 論文作者及單位:Robin Burke(California State University) 我的評分:5顆星
codeforces 185A. Plant(規律)
codeforces 185A. Plant 問經過N年後,向上的三角形的個數。 第一種解法:矩陣遞推可以發現一年後,新的三角形圖形含有的三角形的個數是上一三角形圖形含有的三角形個數的4倍。不過中間的那一塊上下方向轉變了。由此我們可以得到遞推式:設f[n][0]是第N年
PAT刷題集(乙級)1011 A+B和C (15)(15 分)
1011 A+B和C (15)(15 分) 給定區間[-2^31^, 2^31^]內的3個整數A、B和C,請判斷A+B是否大於C。 輸入格式: 輸入第1行給出正整數T(<=10),是測試用例的個數。隨後給出T組測試用例,每組佔一行,順序給出A、B和C。整數間以空格分隔。