http://codeforces.com/contest/742/problem/D 题目大意:有n个人,每个人有重量wi和魅力值bi.然后又有m对朋友关系,朋友关系是传递的,如果a和b是朋友,b和c是朋友,那么a和c就是朋友.现在,把所有能作为朋友的人放在一个集合里面.你现在要开一个party,这个party的容量为W,现在,你每次只能选择一个集合里面的一个人或者选择集合里面的所有人进入这个party.在满足总w <= W的情况下,总魅力值b最大,问魅力值最大是多少? 思路: 定义dp(i,…
题目传送门 /* 题意:两点之间有不同颜色的线连通,问两点间单一颜色连通的路径有几条 DFS:暴力每个颜色,以u走到v为结束标志,累加条数 注意:无向图 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <vector> using namespace std; ; co…
http://codeforces.com/contest/469/problem/D 题目大意: 给你一个长度为n数组,给你两个集合A.B,再给你两个数字a和b.A集合中的每一个数字x都也能在a集合中找到x-a的数字.同理,b集合也一样.问,这个数组能否分成这两个集合?(然后坑点就是集合里面的元素可以为空) 思路一: 首先定义type函数,-1表示不在任何集合内,0表示A集合内,1表示B集合,2表示该元素是a的一半.(之所以要表示成2的原因是因为这个数值很特殊,a-x=x,所以他可以满足A集合…
题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个数和,那么ans = dp[a] - dp[b]: 详细解释:http://blog.csdn.net/catglory/article/details/45932593 */ #include <cstdio> #include <algorithm> #include <cs…
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接快速幂 代码 #include<bits/stdc++.h> using namespace std; long long quickpow(long long m,long long n,long long k) { long long b = 1; while (n > 0) { if…
题目链接 :http://codeforces.com/contest/742/problem/D 题意:给你n个女人的信息重量w和美丽度b,再给你m个关系,要求邀请的女人总重量不超过w 而且如果邀请了一个女人要么就邀请她一个,要么要邀请她还有她所有的朋友. 很明显是一道并查集+背包的问题,并不难.要注意的是背包的写法,由于选择情况有两种 1)只选一个女人 2)选和这个女人有关系的一群女人 于是背包最外层是关系数,即联通块的个数,次外层是背包大小,内层是联通个数(由于选择的要求在一个联通块中 只…
题目链接:http://codeforces.com/contest/742/problem/D D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Just to remind, girls in Arpa's lan…
A. Arpa’s hard exam and Mehrdad’s naive cheat time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Me…
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Problem Description: Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided…
A: 题目大意:给出一个有向图(n<=100),每个点的出度都为1,求最小的t,使得任意两点x,y,如果x走t步后能到y,那么y走t步后到x. 题解: 首先每个点应该都在一个环上,否则无解. 对于大小为k的奇环上的点,满足要求的最小的t是k. 对于大小为k的偶环上的点,满足要求的最小的t是k/2. 对于每个环求最小公倍数即可.  数据范围很小,直接暴力求环就可以了. 代码: #include <iostream> #include <cstdio> #include <…