Linova and Kingdom 题意 现在有一颗n个节点的树,每个节点是一个城市,现在要选出k个城市作为工业城市,其他城市作为旅游城市,现在每个工业城市要派出一名特使前往根节点,每个特使的幸福度为经过的旅游城市的数量,求最大的幸福度总和. 思路 对于某个节点u,如果u是工业城市,那么它的子节点肯定是工业城市. 如果它的某个子节点不是,我们完全可以把它的子节点作为工业城市,而不是u. 我们再看如果选择了u作为工业城市,幸福度发生的变化. 假如本来总幸福度是ans 定义根节点的深度为1,u是不…
Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is a matrix A of size x × y filled with integers. For every , *A**i, …
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价值为s 题解:min(s/n,a)*n+b>=s?YES:NO #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm>…
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test:256 megabytes One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually…
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinis…
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. Afte…
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全部元素的和可以被3整除,问有多少种方法构建出该数组.答案模1000000007 例 输入 2 1 3 输出 3 note:满足的情况只有[1,2],[2,1],[3,3] 解题思路:用dp[i][j]表示长度为i的数组,元素大小在[L,R]之间,并且元素和模3的余数为j的方案数,我们可以计算出[L,…
https://codeforces.com/contest/1113/problem/D 题意 将一个回文串切成一段一段,重新拼接,组成一个新的回文串,问最少切几刀 题解 首先无论奇偶串,最多只会切两刀 然后对于偶数串,看看有没有循环回文串,有的话只需要切一刀 代码 #include<bits/stdc++.h> using namespace std; int n,m,i,j,ok,ans; string s; int main(){ cin>>s;n=s.size(); if…
C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终点,只允许挖一条穿越海的隧道,假设隧道连接的两个陆地分别为(x1,y1),(x2,y2),则挖隧道的花费为\((y1-x1)*(y1-x1)+(y2-x2)*(y2-x2)\) 题解 分别找出和起点,和终点连接的陆地(找联通块),枚举两个点维护最小值 代码 #include<bits/stdc++.h&…
C. Qualification Rounds time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They…