51Nod1081 子段求和(簡單模擬求和)
直接模擬就完事了!
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cmath> #define N 50005 typedef long long ll; using namespace std; int main() { int n; int s[N]; cin>>n; for(int i=0;i<n;i++) cin>>s[i]; int q; cin>>q; while(q--) { int a,b; ll sum=0; cin>>a>>b; for(int i=a-1;i<b+a-1;i++) sum+=s[i]; cout<<sum<<endl; } return 0; }
相關推薦
51Nod1081 子段求和(簡單模擬求和)
直接模擬就完事了! #include<iostream> #include<cstring> #include<algorithm> #include<cst
51 Nod 1065 最小正子段和(前綴和)
sort lin 組成 name turn nod color main tmp 題目鏈接:https://www.51nod.com/onlineJudge/questionCode.html#problemId=1065¬iceId=348062 題意:
HihoCoder1052基因工程(簡單模擬題)
修改方法 ace lib stream 方法 div 最小 mes 大寫 描述 小Hi和小Ho正在進行一項基因工程實驗。他們要修改一段長度為N的DNA序列,使得這段DNA上最前面的K個堿基組成的序列與最後面的K個堿基組成的序列完全一致。 例如對於序列"ATCGA
Climbing Worm HDU - 1049 (簡單模擬題)
#include <stdio.h> int main() { int n, u, d; while(~scanf("%d %d %d", &n, &u, &d)) &nbs
PAT-PAT (Advanced Level) Practise 1005. Spell It Right (20) (簡單模擬題)【一星級】
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. Input Specification:
[分治] 洛谷P1115 最大連續子段和(分治典例)
題目 題目描述 給出一段序列,選出其中連續且非空的一段使得這段和最大。 輸入輸出格式 輸入格式: 輸入檔案maxsum1.in的第一行是一個正整數N,表示了序列的長度。 第2行包含N個絕對值不大於10000的整數A[i],描述了這段序列。 輸出格式
51nod1081 子段求和(字首和)
/* 樹狀陣列求字首和 */ #include <cstdio> #include <iostream> #include <cstring> #include <cmath> using namespace std; typedef lo
程式設計題——虛數求和(簡單結構體的應用)
結構體知識回顧 結構基礎知識 一些結構體的使用誤區 兩種不同函式引數定義的函式 定義結構體,仿照int求和函式 利用結構體 指標重新編寫 結構基礎知識 C的聚合資料型別(aggregate data ty
EF多字段求和(分組/不分組)
ear pre 字段 amount 就是 rec def nth clas 分組多字段求和 query.GroupBy(q => new { q.Year, q.Month }) .Select(q => new { Year
BZOJ4555求和(cdq分治+NTT)
width 枚舉 個數 .com 不為 影響 問題 .cn 特殊 題意: 輸出f(n)對998244353(7 × 17 × 223 + 1)取模的結果。1 ≤ n ≤ 100000 其中S(i,j)是第二類Stirling數,即
多線程練習(簡單模擬火車站多窗口同時售票)
火車 thread art this 模擬 練習 lis span 對象 模擬火車站售票窗口同時售票 public class xianchenglianxi { public static void main(String arg[]){
大魚吃小魚(簡單模擬)
一個 入棧 nco http spa println code tar pre 題目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1289 從左往右將數字壓入棧裏(想象成一個水平向右的棧),如果
命令行參數求和(課程作業01)
string ima 命令行 字符串 令行 int 循環 parse 設計 程序設計思想:使用for循環次將args內各個元素轉為int型累加。 程序流程圖: 源程序代碼: 1 public class GetSum { 2 public static v
bjtu 1819 二哥求和(前綴和)
c++ 輸出數據 alt 接下來 下標 tor math.h AD 分享 題目 1819. 二哥的求和 時間限制 1000 ms 內存限制 128 MB 題目描述 某一天,calfcamel問二哥,有道數學題怎麽做呀?二哥看了一下說我不會呀,於是二哥找到了
LeetCode之楊輝三角二(簡單模擬)
問題描述: 給定一個非負索引 k,其中 k ≤ 33,返回楊輝三角的第 k 行。 在楊輝三角中,每個數是它左上方和右上方的數的和。 示例: 輸入: 3 輸出: [1,3,3,1] 進階: 你可以優化你的演算法
LeetCode之楊輝三角(簡單 模擬)
給定一個非負整數 numRows,生成楊輝三角的前 numRows 行。 在楊輝三角中,每個數是它左上方和右上方的數的和。 示例: 輸入: 5 輸出: [ [1], [1,1], [1,2,1], [1,3,3,1], [
51Nod 1052 - 最大M子段和(DP)
題目連結 http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1052 【題目描述】 N個整陣列成的序列a[1],a[2],a[3],…,a[n],將這N個數劃分為互不相交的M個子段,並且這M個子段的和是最大的。如果
CodeForces - 816C Karen and Game(簡單模擬)
Problem Description On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level
ZZULIOJ 1081: n個數求和 (多例項測試)
題目描述 求n個整數的和。 輸入 輸入第一行是一個整數T,表示有T組測試例項; 每組輸入包括兩行: 第一行一個數n表示接下來會有n個整數; 第二行空格隔開的n個數。 輸出 對於每組
1065 最小正子段和(貪心)
1065 最小正子段和 1 秒 131,072 KB 20 分 3 級題 思路: 一開始以為是動態規劃,但是求的是大於0的子段和,那麼只能暴力求解了 預處理資料,儲存為字首和陣列,然後進行排序,在這之前需要儲存排序前的位置d[i] 然後最重要的,迴圈排完的陣列a[i] 判斷 a[i]-a[i-1]&