题意 https://vjudge.net/problem/CodeForces-1244D 有一棵树,有3种颜色,第i个节点染成第j种颜色的代价是c(i,j),现在要你求出一种染色方案,使得总代价最小,且对于任意三个相邻的节点,颜色不能相同.输出最小代价与其中一种方案.无解输出-1. 思路 首先可以发现当一个点的度数为3,那么它连的三个点的颜色必须互不相同,这样就把三种三色用完了,这个点就染不了了,于是如果存在度大于等于3的点,那么无解. 那么有解的树可以伸直成一条链,我们暴力枚举任意相邻的三…
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just de…
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…
/* 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 问是否可以还原出一个立方体的坐标,注意这一句话: The numbers in the i-th output line must be a permutation of the numbers in i-th input line! 思路: 我们只要对输入的每一行数据进行枚举每一个排列, 然后检查时候能构成立方体就好了! 检查立方体:找到最小的边长的长度 l, 统计边长为l, sqrt(2)*l, sqrt…
题意:n个点,m条无向边,每个边有权值,给你 s 和 t,问你至多删除两条边,让s,t不连通,问方案的权值和最小为多少,并且输出删的边 分析:n<=1000,m是30000  s,t有4种情况(首先定义完全不相同的路径,即两条路径上没有一条边是一样的) 1. s,t本就不连通,输出0即可 2. s,t连通但是只有一条完全不相同的路径 3. s,t连通但是只有两条条完全不相同的路径 4. s,t连通但是有>=3条完全不相同的路径(这种情况无解) 情况1预处理即可,要解决的问题是2,3,4乍一看,…
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R', 'G' and 'B' — colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means chang…
题意:进行若干场比赛,每次比赛两人对决,赢的人得到1分,输的人不得分,先得到t分的人获胜,开始下场比赛,某个人率先赢下s场比赛时, 游戏结束.现在给出n次对决的记录,问可能的s和t有多少种,并按s递增的方式输出. 析:如果枚举s 和 t,那么一定会超时的,所以我们考虑是不是可以不用全枚举.我们只要枚举 t ,然后每次都去计算 s. 首先我们先预处理两个人的获得第 i 分时是第几场比赛.然后每次枚举每个 t,每次我们都是加上t,所以总的时间复杂度为 n*logn. 完全可以接受,注意有几个坑,首先…
暴力. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; struct X { +]; int len; int num; ]; }s[]; int n; int main() { scanf("%d",&n); ;i<=n;i++) { scanf("%s",s[i].s…
A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub got bored, so he invented a game to be played on paper. He writes n integers a1, a2, ..., an. Each of those integers c…
题意 https://vjudge.net/problem/CodeForces-1230C 给了你总共有21张多米诺骨牌,每张牌有两个面,然后给你一个无向图,保证没有环和一个顶点多条边的情况存在.现在让你在这个图中的每个边放多米诺骨牌.有一个放置规则,问你最多能放几张多米诺骨牌上去. 放置规则就是,每个点的权值都是一样的,你在每条边上放的多米诺骨牌,因为它有两个面.需要保证两个面上面的大小就是它指向的点的权值. 如 4 4 1 2 2 3 3 4 4 1 Here is an illustra…