D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ...,…
You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integers in X…
D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ...,…
D. Generating Sets 题目连接: http://codeforces.com/contest/722/problem/D Description You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transfo…
H - Generating Sets Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description You are given a set Y of ndistinct positive integers y1, y2, ..., yn. Set X of ndistinct positive integers x1, x2, ..., xn is…
D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ...,…
[codeforces722D]Generating Sets 试题描述 You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transform X to Y by applying some number of the fol…
Codeforce 722 D. Generating Sets 解析(思維) 今天我們來看看CF722D 題目連結 題目 略,請直接看原題 前言 真的是沒想到... @copyright petjelinux 版權所有 觀看更多正版原始文章請至petjelinux的blog 想法 觀察到,\(x\times2,x\times2+1\)這兩個運算反過來看就是把任一個數字除以\(2\)(因為整數型別會自動捨去小數點,所以整數型別的\(\frac{x}{2}=\lfloor\frac{x}{2}\r…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given a set Y of n distinct positive integers y1, y2, -, yn. Set X of n distinct positive integers x1, x2, -, xn is said to generate set…
C. Heap Operations time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the following…
题目链接:http://codeforces.com/contest/948/problem/C 题目大意:给定长度n(n<=1e5),第一行v[i]表示表示第i堆雪的体积,第二行t[i]表示第1~i天的雪将要消融的体积,一堆雪如果消融到体积为0则消失,求每天消融的雪的体积. 解题思路:用优先队列,第i天就将v[i]+sum[i-1]放入优先队列中,然后初始消融量ans=t[i]*q.size(),假设每堆雪都够消融,然后根据优先队列找到q.top()<=sum[i]即不够消融的,减掉差值.…
<题目链接> 题目大意: 就是一道纯模拟题,具体模拟过程见代码. 解题分析:要掌握不同优先级的优先队列的设置.下面是对优先队列的使用操作详解: priority_queue<int>q 默认为大顶堆. priority_queue<int, vector<int>, less<int>> 大顶堆:表示其他都比堆顶小 priority_queue<int, vector<int>, greater<int>> 小…
题目链接 /* Name: Copyright: Author: Date: 2018/5/2 16:09:54 Description:优先队列 */ #include <iostream> #include <cstdio> #include <vector> #include <cstring> #include <queue> using namespace std; ; int price[MAXN]; struct tshirt{ i…
题目链接:http://codeforces.com/problemset/problem/486/D 题意: 给你一棵树,n个节点,每个节点的点权为a[i]. 问你有多少个连通子图,使得子图中的max(a[i]) - min(a[i]) <= d. ps.连通子图的定义: 如果一个点集V为一个连通子图,则对于任意两点a,b∈V,有a到b路径上的所有点u∈V. 题解: 因为要保证max(a[i]) - min(a[i]) <= d,所以可以人为地选出一个点rt作为点权最大的点. 这样在求以rt…
这种区间的贪心好像都出"烂"了? 不过还是想写一下... 先按照区间左端点排序一下,然后搞个优先队列维护当前最小的右端点. #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=1e5+10; struct asd{ int x,y; }q[N]; bool cmp(asd a, asd b) { if(a.x==b.x) return a.y<b.y; retu…
给定一个序列,每次从序列中找一个长度最大的元素相同的片段,删除它. 如果长度相同,删除最靠左边的那个片段. 问,需要删几次. 用链表处理删除片段.对于删除之后两边又能连成一个片段的那种情况,用set记一下合并就好了. 就是如果这个片段被合并成另一片段了,那么优先队列取到这个的时候就直接pop掉. 本来用自定义的结构体实现的.看了大佬的博客,学会了pair的妙用. pair <a, b>若被排序, a是第一关键字,b是第二关键字. #include <bits/stdc++.h> u…
题目链接 Valid Sets 题目要求我们在一棵树上计符合条件的连通块的个数. 满足该连通块内,点的权值极差小于等于d 树的点数满足 n <= 2000 首先我们先不管这个限制条件,也就是先考虑d为正无穷大的时候的情况. 我们要求出树上所有连通块的个数. 这个时候我们令f[i]为以i为根的子树中的连通块的数目. 此时状态转移方程为 f[x] = f[x] * (f[u] + 1) 其中f[x]初始值为1,u为x的儿子 最后f[1]的值(我们假设1为根结点)即为答案 时间复杂度为O(n) 注意到…
D. Valid Sets time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree…
题目大意:给出n个数,要求将n个数分配到两个集合中,集合0中的元素x,要求A-x也再0中,同理1集合. 写了几个版本号,一直WA在第8组数据...最后參考下ans,写了并查集过了 学到:1.注意离散的逻辑思维,官方答案的 从条件推逆否命题 2.并查集做法:fa[find(i)]=mp[a-p[i]] ? find(a-p[i]) : find(n+2); 3.离散化然后hash的方法,用map时间还是承受得住的,写起来也简单 //#pragma comment(linker, "/STACK:1…
题面传送门 题意: 你有一个可重集 \(S=\{a_1,a_2,\dots,a_n\}\),你要把它划分成两个可重集 \(S_1,S_2\) 使得 \(S\) 中每个元素都恰好属于 \(S_1\) 与 \(S_2\) 之一. 记 \(X_1\) 为 \(S_1\) 中所有元素的异或和,\(X_2\) 为 \(S_2\) 中所有元素的异或和. 最大化 \(X_1+X_2\),如果有多种分配方案,再最小化 \(X_1\). \(n \in [1,10^5],a_i \in [1,10^{18}]\)…
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format…
C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the ar…
主题链接:http://acm.timus.ru/problem.aspx?space=1&num=1727 1727. Znaika's Magic Numbers Time limit: 0.5 second Memory limit: 64 MB Znaika has many interests. For example, now he is investigating the properties of number sets. Znaika writes down some set…
最近做了好多CF的题的说,很多cf的题都很有启发性觉得很有必要总结一下,再加上上次写题解因为太简单被老师骂了,所以这次决定总结一下,也发表一下停课一星期的感想= = Codeforces 261E Maxim and Calculator 描述:有两个变量a和b,初始值为1和0,每次有两种操作,一个是a=a*b,另一个是b++,求有多少个l<a<r能在p步内达到(p<=100,r<1e9) 首先观察到p最大为100,也就是说最大质因数小于p,打表可得一共大概只有300万个数 考虑d…
强连通分量的应用,详见<挑战程序设计>P324 例题1:HDU Peaceful Commission 思路:强连通分量分解,看有没有两个同一个国家的代表在一个强连通分量里,如果有,就是NIE.这个不是关键,关键是怎么输出,输出还要用一下dfs,把所有能到达的点标记一下,顺便判断一下和之前有没有矛盾,有矛盾的话所有被标记的点又要重新标记回去.其实这道题可以不用强连通分量分解,直接dfs. 代码1(强连通分量分解+dfs): #include<bits/stdc++.h> using…
题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给排名在前面的的队,给完后自己的气球数减少,继续跟之前排在第一队后面的队比较,考虑是否加入队列,每次记录最好的名次. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> us…
D. Valid Sets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem/D Description As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consist…
C. Developing Skills Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/problem/C Description Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n dif…
B. Two Sets Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/B Description Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must…
A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minut…