CF405D Toy Sum

2024-03-04 07:32
文章标签 sum toy cf405d

本文主要是介绍CF405D Toy Sum,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

刚看见的时候貌似是一道很难做的题…题面十分的玄学,不能重选的要求也十分难搞…

但是,可以发现N<=5*105从中可以不难发现一旦不能直接取时便会一定有一对正好和为1e6-1

#include<bits/stdc++.h>
using namespace std;
const int maxS=1000005;
int a[maxS],b[maxS],answer[maxS],S,N;
bool boo[maxS];
int main()
{S=1000000;scanf("%d",&N);int i;for(i=1;i<=N;i++){scanf("%d",&a[i]);boo[a[i]]=1;//不能选了}int cnt=0;int full=0;//成对不能选的个数for(i=1;i<=N;i++)if(!boo[S-a[i]+1])//直接取{answer[++cnt]=S-a[i]+1;boo[S-a[i]+1]=1;}elsefull++;full/=2;//计算了两次..for(i=1;i<=(S+1)/2;i++)if(!boo[i]&&!boo[S-i+1])//成对可以取的{if(!full)break;//不需要了full--;answer[++cnt]=i;answer[++cnt]=S-i+1;}printf("%d\n",cnt);//输出个数for(i=1;i<=cnt;i++)printf("%d ",answer[i]);//输出序列return 0;
}

算是一道小清新的构造题…吧…

这篇关于CF405D Toy Sum的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/772458

相关文章

最大流=最小割=最小点权覆盖集=sum-最大点权独立集

二分图最小点覆盖和最大独立集都可以转化为最大匹配求解。 在这个基础上,把每个点赋予一个非负的权值,这两个问题就转化为:二分图最小点权覆盖和二分图最大点权独立集。   二分图最小点权覆盖     从x或者y集合中选取一些点,使这些点覆盖所有的边,并且选出来的点的权值尽可能小。 建模:     原二分图中的边(u,v)替换为容量为INF的有向边(u,v),设立源点s和汇点t

如何导入sun.misc.BASE64Encoder和sum.misc.BASE64Decoder

右击项目名--->Build Path--->Configure Build Path...--->java Build Path--->Access rules:1 rule defined,added to all librar...   --->Edit --->Add...

18. 4 Sum

题目: 解答: 与之前的三数之和的解法类似,也是先排序,然后不断剔除不可能的条件,最后两个参数,通过两头求和计算得出。 代码: class Solution {public:vector<vector<int>> fourSum(vector<int>& nums, int target) {vector<vector<int>> result;int len = nums.size

apt-get update更新源时,出现“Hash Sum mismatch”问题

转载自:apt-get update更新源时,出现“Hash Sum mismatch”问题 当使用apt-get update更新源时,出现下面“Hash Sum mismatch”的报错,具体如下: root@localhost:~# apt-get update ...... ...... W: Failed to fetch http://us.archive.ubuntu.com/ub

[LeetCode] 303. Range Sum Query - Immutable

题:https://leetcode.com/problems/range-sum-query-immutable/description/ 题目 Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums

[LeetCode] 64. Minimum Path Sum

题:https://leetcode.com/problems/minimum-path-sum/description/ 题目 Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers

[LeetCode] 404. Sum of Left Leaves

题:https://leetcode.com/problems/sum-of-left-leaves/description/ 题目 Find the sum of all left leaves in a given binary tree. Example: 3/ \9 20/ \15 7There are two left leaves in the binary t

数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

Sum  Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704   Mean:  给定一个大整数N,求1到N中每个数的因式分解个数的总和。   analyse: N可达10^100000,只能用数学方法来做。 首先想到的是找规律。通过枚举小数据来找规律,发现其实answer=pow(2,n-1);

LeetCode - 40. Combination Sum II

40. Combination Sum II  Problem's Link  ---------------------------------------------------------------------------- Mean:  给你一个待选集合s和一个数n,选出所有相加之和为n的组合.(每个元素只能选一次) analyse: 递归求解. 在递归进入

LeetCode - 39. Combination Sum

39. Combination Sum  Problem's Link  ---------------------------------------------------------------------------- Mean:  给你一个待选集合s和一个数n,让你找出集合s中相加之和为n的所有组合.(每个数可选多次) analyse: 作此题需对递归有一定的