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 //sum是a的字首和
找個規律——
發現 sumi=⌊2i−1⌋×(−1)i
然後就可以求出 sumL和 sumR了,相減即可。
程式碼:
#include<bits/stdc++.h>
using namespace std;
#define read(x) scanf("%d",&x)
int main() {
int T;
read(T);
while(T--) {
int L,R;
read(L),read(R);
printf("%d\n",((R+1)/2*((R&1)?-1:1))-((L)/2*((L&1)?1:-1)));
}
return 0;
}
相關推薦
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
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
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
(規律)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) 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
gym-101343I-Husam and the Broken Present 1
cnblogs bit using space namespace for bsp pri () 1 ///水題 2 #include <bits/stdc++.h> 3 using namespace std; 4 int main() 5 {
<gym101343J. Husam and the Broken Present 2> (狀壓DP)
一起 names 都是 預處理 ret %d 註意 一個 size 題意:給定n個串 每個串長度不超過100 找到一個新串 使得這n個串都是它的字串 輸出這個新串的最小長度 題解:n是15 n的階乘的復雜度肯定不行 就想到了2的15次方的復雜度 想到了狀壓
CF 1084 D. The Fair Nut and the Best Path
D. The Fair Nut and the Best Path https://codeforces.com/contest/1084/problem/D 題意: 在一棵樹內找一條路徑,使得從起點到終點的最後剩下的油最多。(中途沒油了不能再走了,可以在每個點加wi升油,減少的油量為路徑長度)。
Codeforces Round #526 D - The Fair Nut and the Best Path /// 樹上兩點間路徑花費
題目大意: 給定一棵樹 樹上每個點有對應的點權 樹上每條邊有對應的邊權 經過一個點可得到點權 經過一條邊必須花費邊權 即從u到v 最終得分=u的點權-u到v的邊權+v的點權 求樹上一條路徑使得得分最大 看註釋 #include <bits/stdc++.h> #
CodeForces 1084D The Fair Nut and the Best Path
The Fair Nut and the Best Path 題意:求路徑上的 點權和 - 邊權和 最大, 然後不能存在某個點為負數。 題解: dfs一遍, 求所有兒子走到這個點的最大值和次大值。 我們需要明白如果可以從u -> v 那麼一定可以從 v -> u, 當然 指的是
【樹的DFS】codeforces1084D The Fair Nut and the Best Path
D. The Fair Nut and the Best Path time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output The Fa
First Look at Android Emulator 2.0, the biggest and the best update yet in years
I believe that all Android developers would agree that the biggest thing announced in Android Dev Summit 2015 was Android Studio 2.0 and
Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path 樹形dp
題目連結: 傳送門 題意: 每個點有正權值ai,每條邊有負權值wi,你可以隨意選擇一條路徑,使得這條路徑的總權值最大,要求每個點每條邊至多都只能走一次。 思路: 一個頂點可以是路徑中的根節點或者是中間節點。 所以,設立兩個陣列,dpr,dpm. dpr表示為根節點的最
D. The Fair Nut and the Best Path(樹形dp)
D. The Fair Nut and the Best Path http://codeforces.com/contest/1084/problem/D time limit per test 3 seconds memory limit per test 256 meg
Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path 樹上dp
push ret 起點 air and second eof The bit D. The Fair Nut and the Best Path 題意:給出一張圖 點有權值 邊也要權值 從任意點出發到任意點結束 到每個點的時候都可以獲得每個點的權值,而從邊走的時候都要消耗改
The Best Free Scrum Learning Resources, Guides and Articles
The Best Free Scrum Learning Resources, Guides and Articles Guide - Scrum Guides [PDF Download] Developed and sustained by Scrum creators: Ken Sch
Ask HN: Whats the best desktop cfg for ML and Data science side project as R&D?
Should I go for a) All in one powerful desktop b) multiple PCs with RAM in the 4-8 GB range? How to decide?
10 of the best dating sites for introverts, wallflowers, and shy people
Online dating is basically the best thing that ever happened to introverts. You can now scan for a potential mate without ever leaving the comfort zone tha
The past, present and future of humankind
Life: a concoction of dual realities, myths and storiesCredit: TEDFor starters, Yuval Noah Harari is one of the skeptical thinkers who claims that humans k