SPOJ:Elegant Permuted Sum(贪心)】的更多相关文章

Special Thanks: Jane Alam Jan*At moment in University of Texas at San Antonio - USA You will be given n integers A1A2A3...An. Find a permutation of these n integers so that summation of the absolute differences between adjacent elements is maximized.…
Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer requires knowledge in many fields, because problems in this contest may use physics, biology, and even musicology as background. And now in this prob…
KPSUM - The Sum One of your friends wrote numbers 1, 2, 3, ..., N on the sheet of paper. After that he placed signs + and - between every pair of adjacent digits alternately. Now he wants to find the value of the expression he has made. Help him. For…
#include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<<1,L,mid #define rson rt<<1|1,mid+1,R /* AC 水题 题意:给出n个数,两种操作 U i x 将第i个数改成x Q x y 查询[x,y]中两个数的和的最大值,这两个数不能为同一个 即只要求该区间第一大和第二大的数,他们的和即为答案 */ using nam…
题意是求: $\sum_{i = 1}^{n}lcm(i, n)$ $= \sum_{i = 1}^{n}\frac{ni}{gcd(i, n)}$ $= n\sum_{i = 1}^{n}\frac{i}{gcd(i, n)}$ $= n\sum_{d|n}\sum_{i = 1}^{n}d*[gcd(i, n)==d]$ $= n\sum_{d|n}\sum_{i = 1}^{\frac{n}{d}}i*[gcd(i, \frac{n}{d})==1]$ $= n\sum_{d|n}\sum…
Problem statement: A string is said to be “PATHETIC” if all the characters in it are repeated the same number of times. You are given a string of length n, what is the minimum number of changes required to make a string “PATHETIC”. The string has onl…
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest pal…
Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大.Prometheus 为了让 Zeus 看到人类的伟大,随即同意 Zeus 可以向人类求助.你能证明人类的智慧么?   Input 输入包含若干组测试数据,每组测试…
传送门 怎么说呢,想了几个小时没做出来实在可惜. \(\color{Red}{首先肯定想到暴力嘛!但是x定值有那么多值可以取,怎么办呢?}\) 但是题目中有一个很关键的条件 \[a[i]>=1\&\&a[i]<=k \] 所以,在最坏情况下我们的答案会是\(n/2-s.(s为\frac{n}{2}对数中和为k+1的总数)\) \(\color{Purple}{为什么?因为不管怎样,对于所有的\frac{n}{2}对数,我都可以改变一个数使得定值变成K+1.}\) \[若改变一个…
题意:有\(n\)个数,选择某一对数使二者分别\(or\)和\(and\)得到两个新值,求操作后所有数平方和的最大值. 题解:不难发现每次操作后,两个数的二进制表示下的\(1\)的个数总是不变的,所以要让平方最大,那么只能使大的尽可能大,那我们就统计每个数二进制下的每一位上\(1\)的个数,然后每个数的位置都尽可能的分配\(1\)就行了. 代码: ll n,x; ll cnt[N]; ll ans; int main() { ios::sync_with_stdio(false);cin.tie…
Canonical Coin Systems 题目描述 A coin system S is a finite (nonempty) set of distinct positive integers corresponding to coin values, also called denominations, in a real or imagined monetary system. For example, the coin system in common use in Canada…
问题 C: Canonical Coin Systems 时间限制: 1 Sec  内存限制: 128 MB 提交: 200  解决: 31 [提交] [状态] [命题人:admin] 题目描述 A coin system S is a finite (nonempty) set of distinct positive integers corresponding to coin values, also called denominations, in a real or imagined…
看到老外评论区中说,这场的难度估计是\(div.1\)和\(div.1.5\)的合并 A. Circle Coloring #构造 题目链接 题意 给定三个长度为\(n\)数组\(a,b,c\),要你从三个数组中选取元素构造出长度也为\(n\)的数组,内部相邻元素互不相等(包括下标\(1\)和\(n\)) 分析 注意是一个圈中相邻元素互不相等. #include <algorithm> #include <cstdio> #include <cstring> #incl…
Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 1555    Accepted Submission(s): 657 Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Ze…
题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can(int m, int s)函数,来判断是否存在一个m位数其各位数字之和为s 这里先不考虑前导0的事,代码看起来可能是这个样子的: bool can(int m, int s) { && s <= m*); } 比如我们现在要求满足要求的最小整数,从最左边的数开始从0到9开始试,如果后面的…
Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Description You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m…
http://www.spoj.com/problems/SEGSQRSS/ SPOJ Problem Set (classical) 11840. Sum of Squares with Segment Tree Problem code: SEGSQRSS Segment trees are extremely useful.  In particular "Lazy Propagation" (i.e. see here, for example) allows one to c…
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define CLR(a,b) memset((a),(b),sizeof(…
题目链接: Elegant Construction Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description Being an ACMer requires knowledge in many fields, because problems in this contest may use physics, biology, and even…
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base with…
2021-01-29 题目链接: Educational Codeforces Round 103 (Rated for Div. 2) 题目 A. K-divisible Sum You are given two integers nn and kk. You should create an array of nn positive integers a1,a2,-,ana1,a2,-,an such that the sum (a1+a2+⋯+an)(a1+a2+⋯+an) is div…
BACKUP - Backup Files no tags  You run an IT company that backs up computer data for large offices. Backing up data is not fun, and so you design your system so that the different offices can back up each others' data while you sit at home and play c…
糟烂的代码啊...  这个题目思路很简单——末位只可能为0和5,所有数字的和肯定被3整除 没有0和5的肯定不行 否则,把所有数字求和 如果被3整除,则从大到小输出 如果除3余1,则按以下顺序——删1:删4:删7:删2.5.8中的2个(特别注意如果没有0要保留一个5) 如果除3余2,则按以下顺序——删2:删5(特别注意如果没有0要保留):删8:删1.4.7中的2个 下面是糟烂的代码—— //糟烂代码总结 —— 没有章法,思路不清,逻辑性太高,导致找不出错 //以后写代码引以为戒 #include…
Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root has index 11. Each vertex vv initially had an integer number av≥0av≥0 written on it. For every vertex vv Mitya has computed svsv: the sum of all values written on the vert…
题目链接;http://codeforces.com/contest/1099/problem/D 题目大意:给出一棵树,每个节点到根节点的路径上经过的所有点的权值之和,其深度为偶数的节点的信息全部擦除了,也就是用-1表示,让你求最终所有点权之和(要求最小) 具体思路:对于每一个节点,这个点到根节点的权值最小的时候是他的所有的根节点的最小值,然后一路更新上去就可以了,最后求值得时候,我们求父亲节点和子节点之间的差就可以了, 如果差值为负值就是非法情况. AC代码: #include<bits/s…
D. Sum in the tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root has index 11. Each vertex vv initially had…
题意:求出\(n\)拆分成若干个数使其连乘最大的值 本题是之江学院网络赛的原题,计算规模大一点,看到EMAXX推荐就做了 忘了大一那会是怎么用均值不等式推出结果的(还给老师系列) 结论倒还记得:贪心分解3,不够就用2凑 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #…
C. Little Girl and Maximum Sum time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The little girl loves the problems on array queries very much. One day she came across a rather well-known proble…
You have two integers L and R, and you are required to find the max xor value of a and b where L <= a <= R and L <= b <= R Input Two integers in a line. L, R <= 1e9 Output One integer, the answer Example Input: 1 10 Output: 15 题意: 给定L,R,X1^…
Shadowman loves to collect box but his roommates woogieman and itman don't like box and so shadowman wants to hide boxes as many as possible. A box can be kept hidden inside of another box if and only if the box in which it will be held is empty and…