原题链接 简要题意: 你可以无限次的把该数组的一个前缀和后缀 \(\times -1\),问最终的最大序列和. 这题盲目WA了数次才知道本质 这题89个数据吊打std CF真好啊,发现一个错后面就不测了 下面,就以我艰辛的思维历程来构造本篇博客. 算法一 盲猜:所有数都可以变成正数. 然后绝对值相加. 连样例也没测. 然后,\(\frac{2}{89} pts\). 只过了前两个样例,第三个就死了. #pragma GCC optimize(2) #include<bits/stdc++.h>…
传送门 Description 给你一个数列\(A\),你可以选择任意一个前缀和任意一个后缀,前缀后缀可重合.给他们乘\(-1\).求最大能获得的序列和. Input 第一行是一个数\(n\)代表数列长度 第二行\(n\)个数字,代表序列的元素 Output 一个数字代表答案 Hint \(1~\leq~n~\leq~10^5\) Solution 发现重合的部分相当于没有修改.于是不妨设前后缀没有重合. 设修改的原序列前缀和为\(A\),后缀和为\(B\),未修改的部分为\(C\),序列和为\…
目录: 1.1093D. Beautiful Graph(DFS染色) 2.514C - Watto and Mechanism(Tire) 3.69E.Subsegments(STL) 4.25C. Roads in Berland(最短路松弛操作) 5.128B. String Problem (floyd预处理) 6.33C.Wonderful Randomized Sum(思维) 7.1292B.Aroma's Search (暴力+思维) 8.1286 A.Garland(DP) 9.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5531 Problem Description Archaeologists find ruins of Ancient ACM Civilization, and they want to rebuild it. The ruins form a closed path on an x-y plane, which has n endpoints. The endpoints locate on (…
Two Sum 題目連結 官網題目說明: 解法: 從給定的一組值內找出第一組兩數相加剛好等於給定的目標值,暴力解很簡單(只會這樣= =),兩個迴圈,只要找到相加的值就跳出. /// <summary> /// 暴力解O(n) /// </summary> /// <param name="nums"></param> /// <param name="target"></param> /// &…
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2],…
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
题目链接:Sum 嗯--不要在意--我发这篇博客只是为了保存一下杜教筛的板子的-- 你说你不会杜教筛?有一篇博客写的很好,看完应该就会了-- 这道题就是杜教筛板子题,也没什么好讲的-- 下面贴代码(不知道为什么我的常数就是大): #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define File(s) freo…
You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to…