codeforces 665D Simple Subset】的更多相关文章

题目链接: http://codeforces.com/problemset/problem/665/D 题意: 给定序列,从中找出最大的子集,使得子集中的数两两相加均为质数. 分析: 貌似有用最大团做的.可是不会,名字太难听也不是很想学. n只有1000,暴力一发. 如果集合中有1的话,把所有1都放进去,我们最多再找一个偶数. 如果不考虑1的话,两个奇数,两个偶数相加均为偶数,所以最多找一个奇数和一个偶数. 枚举之后判断一下是否为质数就好了. 我觉得整个序列找不到两两相加为质数的时候的说明不是…
题意: 给你n个数,让你从中选一个子集要求子集中的任何两个数相加都是质数. 思路: 一开始把自己坑了,各种想,后来发现一个简单的性质,那就是两个数相加的必要条件是这两个数之中必定一个奇数一个偶数,(除了含有1 集合以外,1+1等于2也是质数). 考虑两种情况,有1存在和1不存在这两种. 很显然1存在的情况下,所有的1都可以同时在集合中出现,要想集合最大不能加奇数,只能加偶数,那么我们看原始集合中是否有偶数加一是素数. 不考虑1的情况下,这样的子集最大是2,只有存在一个奇数一个偶数相加是质数的情况…
题目链接 给一个数列, 让你选出其中的m个数, 使得选出的数中任意两个数之和都为质数, m尽可能的大. 首先, 除了1以外的任意两个相同的数相加结果都不是质数. 然后, 不考虑1的话, 选出的数的个数不大于2. 假设我们选了3个数, a1, a2, a3. a1+a2是质数的话, 那么a1, a2中一个为奇数一个为偶数. 那么如果a3无论为奇数或偶数都无法满足条件了. 所以我们按1出现的次数分类讨论一下就好了. #include <iostream> #include <vector&g…
//题意:给你n个数(可能有重复),问你最多可以取出多少个数使得任意两个数之和为质数.//题解:以为是个C(2,n)复杂度,结果手摸几组,发现从奇偶性考虑,只有两种情况:有1,可以取出所有的1,并可以再取一个偶数(如果这个偶数+1是质数).没有1,如果取了一个奇质数,那只能再拿一个2(如果有2的话). 坑:一度把题目记错了,以为输入的是质数,结果比赛的时候一直wa到orz ac代码: #include<iostream> #include<stdio.h> #include<…
D. Simple Subset time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i,  j) (1  ≤ i  <  j …
D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i,  j) (1  ≤ i  <  j ≤ k), xi  +  xj is a prime. You are given a…
题目链接: D. Simple Subset time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i,  j) (1  ≤ i …
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数字有a[i]个2, b[i] 个5 以其中一维作体积另一维作价值01背包即可 */ #include <bits/stdc++.h> using namespace std; int dp[205][20005]; int get2(long long x) { int s = 0; while…
E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard input output:standard output Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list…
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible. Input…
CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecules Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u id=46665" class="login ui-button ui-widget ui-state-default…
原题: http://codeforces.com/contest/570/problem/B 题目: Simple Game time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output One day Misha and Andrew were playing a very simple game. First, each player choo…
题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任何一个节点,并且不超过一次. 因为是无向图,而且是环,即为连通分量,所以模型转化为求点双连通分量,依据题意求得的点双连通分量需要满足题目simple cycle的定义,所以当一个点双连通分量的边数量和点数量相等时才能构成simple cycle,在tarjan求割点的时候,需要存储点双联通分量的点和…
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom in the molecule must be equal to its valence number. 给定三个原子的化学价,规定化学价数等于该原子与另外两个原子所连接的原子键之和. 又一次把简单问题复杂化了.....(以下注释部分读者可以忽略) /* 一开始三重循环枚举,绝对超时(10^6 * 1…
837D - Round Subset 思路:dp.0是由2*5产生的. ①dp[i][j]表示选i个数,因子2的个数为j时因子5的个数. 状态转移方程:dp[i][j]=max(dp[i][j],dp[i-1][j-c2]+c5). 初始化:dp[0][0]=0,dp[i][j]=-INF(i!=0||j!=0).因为所有状态都是由dp[0][0]转移过来的,所以除此之外的dp[i][j]都得初始化为-INF,防止对答案产生影响. 代码1: #include<bits/stdc++.h> u…
题目链接: http://codeforces.com/contest/665/problem/C 题意: 改变最少的字符,使得最终序列无相同的连续的字符. 分析: 对每一个与前一个字符相同的字符,枚举满足条件的字符进行替换. 代码: #include<iostream> using namespace std; int main (void) { string s;cin>>s; int n = s.length(); for(int i = 1; i < n; i++){…
题目链接  Round Subset 题意  在n个数中选择k个数,求这k个数乘积末尾0个数的最大值. 首先我们预处理出每个数5的因子个数c[i]和2的因子个数d[i] 然后就可以背包了. 设f[i][j]为选i个数,5的因子总和为j时,2的因子总和的最大值. 则状态转移方程为 $f[i][j] = max(f[i - 1][j - c[k]] + d[k])$ 注意边界条件 时间复杂度$O(5200nk)$ #include <bits/stdc++.h> using namespace s…
题意: 给你一堆无序数,寻找它的一个子堆,使得子堆的平均数减中位数最大. 数字的个数n<=2e5 0<=xi<=1e6. 思路: 首先可以证明这堆数一定是奇数个,证明方法是尝试在奇数个的有序数列中加入一个数字求平均值和中位数各增加了多少.然后比较一下. 也可以考虑偶数个的序列去掉中间两个中较大的数,差值不会减小. 所以中位数一定是原先堆里的数,我们可以枚举每一个数,然后二分查找范围. 二分查找范围的原理是,随着字串长度的增加,那么差值是先增大后减小的,所以我们枚举某点和它相邻的点的斜率(…
题目链接 给n个数, 让你去掉一些数, 使得剩下的数的平均值-中位数的差值最大. 先将数组排序, 然后枚举每一个数作为中位数的情况, 对于每个枚举的数, 三分它的左右区间长度找到一个平均值最大的情况, 平均值最大, 肯定是它左边的数是靠近他的那几个数, 右边的数是最右边的那几个数. 然后所有情况取最大值. 三分的写法lmid = (l*2+r)/2, rmid = (l+r*2+2)/3, 学到了. 并且求平均值最好不要除,比如说平均数-中位数, 那么写成   这几个数的和-中位数*长度. #i…
相同的一段字母变一下就可以. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; +; char s[maxn…
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; scanf("%d%d%d",&a,&b,&c); int ab=a+b-c,bc=b+c-a,ac=a+c-b; if(ab>=0&&bc>=0&&ac>=0&&ab%2==0&&bc%2==0&&ac%2==0)…
先算出每个数的pop1(twonum),pop(fivenum)然后DP ans[i][j]表示选i个数有j个2时最多有多少个5 转移方程是 ;j--) { ;w++) { ans[j][w]=max(ans[j][w],ans[j-][w-pop1]+pop); } } AC程序: #include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #in…
题意 给出一张无向图,让你找出一个大小为\(k\)的子团或者找出一个导出子图,使得图中的每个点的度数至少为\(k\). 思路 首先有个重要观察,当\(\frac{k(k-1)}{2} > m\)时,无解,因为无论是满足要求子团还是导出子图至少有\(\frac{k(k-1)}{2}\)条边,于是我们把\(k\)降到了\(O(\sqrt{m})\)的级别. 对于导出子图,我们用类似拓扑序的方法一次将度数\(<k\)的点删去,剩下的点就是所求导出子图.当我们从队列中取出一个度数是\(k-1\)的点的…
题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or…
Simple Matching LPeg is a powerful notation for matching text data, which is more capable than Lua string patterns and standard regular expressions. However, like any language you need to know the basic words and how to combine them. The best way to…
[quote ]ffmpeg, gstreamer, Raspberry Pi, Windows Desktop streaming http://blog.pi3g.com/2013/08/ffmpeg-gstreamer-raspberry-pi-windows-desktop-streaming/ This is a work still in progress with unsatisfactory results (image quality, delay, very low fram…
OpenID Connect是什么?OpenID Connect(目前版本是1.0)是OAuth 2.0协议(可参考本人此篇:OAuth 2.0 / RCF6749 协议解读)之上的简单身份层,用 API 进行身份交互的框架,允许客户端根据授权服务器的认证结果最终确认用户的身份,以及获取基本的用户信息:它支持包括Web.移动.JavaScript在内的所有客户端类型:它是可扩展的协议,允许你使用某些可选功能,如身份数据加密.OpenID提供商发现.会话管理 OpenID Connect vs O…
Welcome to OpenID Connect What is OpenID Connect? OpenID Connect 1.0 is a simple identity layer on top of the OAuth 2.0 protocol. It allows Clients to verify the identity of the End-User based on the authentication performed by an Authorization Serve…
A system management mode (SMM) of operating a processor includes only a basic set of hardwired hooks or mechanisms in the processor for supporting SMM. Most of SMM functionality, such as the processing actions performed when entering and exiting SMM,…
E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作,每次操作将(l,r)内的字符升序或降序排列,输出q次操作后的字符串. analyse: 基本思想是计数排序. 所谓计数排序,是对一个元素分布较集中的数字集群进行排序的算法,时间复杂度为O(n),但使用条件很苛刻.首先对n个数扫一遍,映射出每个数字出现的次数,然后再O(n)扫一遍处理出:对于数字ai,…