解题:CF1130E Wrong Answer】的更多相关文章

题面 巧妙构造题 这种题一定要限制一个条件,使得在这个条件下能推出要叉的代码的式子 令序列$a$的第一个元素为负,其余元素为正,且保证序列中至少有两个元素,那么Alice的代码将会从第二个元素开始计算,得到$(n-1)*(sum-a[1])$的答案.而这里答案实际可能有两种,Alice那样的$(n-1)*(sum-a[1])$和全部选取的$n*sum$(因为后面全是正的所以其他方案一定劣于这两种).我们后者-前者作个差得到$sum-n-a[1]$,不妨令$a[1]=-1$,那么只需要构造一个长度…
E Wrong Answer 注意到 \(n\geq 2\) 时才可能有解,可以按如下方式构造一个 \(a_{1,2\dots n}\): 令 \(a_1=-1\) ,而后面的数都为正.记 \(s=\sum_{i=2}^{n} a_i\),显然题目中的程序给出的答案是 \(s*(n-1)\) . 为使这个答案比正确答案少 \(k\) ,那么正确答案只能是 \((s-1)*n\). \[ s(n-1)+k=(s-1)n\\ s=k+n \] 由于我们可以放 \(1\) 个 \(-1\) , \(1…
题意 题目链接 Sol 对构造一无所知... 题解的方法比较神仙,,设第一个位置为\(-1\),\(S = \sum_{i=1}^n a_i\) 那么我们要让\(N * S - (N - 1) * (S + 1) = K\) 固定\(N\)之后可以直接解出\(S\)... #include<bits/stdc++.h> #define Pair pair<LL, LL> #define MP(x, y) make_pair(x, y) #define fi first #defin…
18. 4Sum Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note For example, given array S = [1, 0, -1, 0, -2, 2], and targ…
手速慢...思考速度慢...是撑不到最后boss的...共勉 ========================我是日常分割线=========================== 1010. Radix (25) /* date:2016-09-05 author:CheerM title:Radix(25) 题目描述: Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be…
话说cdsn要是前面插入源代码又什么都不放就会出现奇怪的源代码?不知道是哪个网页的 407. BLOCKS 时间限制 1000 ms 内存限制 65536 KB 题目描述 给定一个N∗M的矩阵,求问里面有多少个由'#'组成的矩形,"There are 5 ships.",若是里面有一个不是矩形的联通块,则输出"So Sad" 输入格式 1≤n,m≤1000 有多组数据,EOF结束. 输出格式 每行对应一个answer 输入样例 6 8 .....#.# ##....…
题目是POJ1001 Exponentiation  虽然是小数的幂 最终还是转化为大整数的乘法 这道题要考虑的边界情况比较多 做这道题的时候,我分析了 网上的两个解题报告,发现都有错误,说明OJ对于错误的判断还不够严厉. 对边界情况的讨论其实应该是思维严密的表现,当然这并不能表明我写的一点错误都没有,只是多多分析一下还是很有好处的. #include <iostream> #include <fstream> #include <string> #include &l…
922. Sort Array By Parity II 题目描述 Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even. You may re…
Array *532. K-diff Pairs in an Array 方案一:暴力搜索, N平方的时间复杂度,空间复杂度N 数组长度为10000,使用O(N平方)的解法担心TLE,不建议使用,尽管最终验证还是可以过. 方案二:哈希 时间复杂度N 空间复杂度N *1.two sum 思路: 使用hash, 顺序遍历数组,并记录每一个出现过的元素值和其下标,当遍历到当前元素时,查找target-当前元素值 是否出现在map中,存在则返回结果 *16. 3Sum Closest 思路一:暴力 fo…
1. Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth…