Naming Company CodeForces - 794C】的更多相关文章

Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play…
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play…
http://codeforces.com/contest/794/problem/C Description Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the…
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play…
[题目链接]:http://codeforces.com/contest/794/problem/C [题意] 有n个位置; 两个人; 每个人都有n个字符组成的集合s1,s2(可以有重复元素); 然后两人轮流从各自的集合中取出一个字符; 把它放在这n个位置中的任意一个位置; 其中一个人想要让这n个字符组成的字符串字典序尽量小; 另外一个人则想让他尽量大; 问你最后字符串会变成什么样 [题解] s1和s2是两个人的集合 可以先把s1升序排; 然后s2降序排; 设ls1,ls2分别为s1和s2最左的…
http://codeforces.com/contest/794/problem/C 题意: 有两个人要为公司起名字,每个人手中都有n个字符,现在要取一个n个字符长度的公司名.两人轮流取名,每次选择一个字符,可以任意选择放在1~n还未放置字符的位置上,每个字符限用一次. 现在第一个人希望公司名字典序越小越好,而第二个人希望字典序越大越好.输出最后的公司名. 思路: 首先肯定是要排序的,第一个人肯定去用前面最小的几个,而第二个人肯定去用前面最大的几个. 轮到第一个人时,我们首先将他手中最小的字符…
题目链接:http://codeforces.com/contest/794/problem/C 题意:有两个人每个人都有一个长度为n的字符串,两人轮流拿出一个字符串,放在一个长度为n的字符串的指定位置中,第一个 人他想让最后组成的字符串尽可能小,另一个人想要字符串尽可能的大.他们互相知道各自手中有什么字符串,最后输出组成的 字符串 #include <iostream> #include <cstring> #include <string> #include <…
考虑两个人,先把各自的集合排个序,丢掉一半,因为比较劣的那一半一定用不到. 然后贪心地放,只有两种决策,要么把一个最优的放在开头,要么把一个最劣的放在结尾. 如果我的最优的比对方所有的都劣(或等于),我就把我最劣的往结尾放.否则我把我最优的往开头放. 用multiset维护两人的集合即可. #include<cstdio> #include<cstring> #include<algorithm> #include<set> using namespace…
http://codeforces.com/contest/794/problem/C 题意:A,B两人各有长度为n的字符串,轮流向空字符串C中放字母,A尽可能让字符串字典序小,B尽可能让字符串字典序大,A,B都知道对方的情况:A先手. 首先,A要C的字典序大,B要C的字典序小,所以先贪心,A的按从小到大排序,B的按从大到小排序. 那么现在我们已经知道了A,B分别要选择放到C的字符. 接下来博弈: B的最大字符等于小于A的最小字符: A走:A一定要B放到前面,所以A尽可能放到后面,放哪个呢?当然…
老年人题解,语言python3 A - Bank Robbery 题意:给你ABC,以及n个数,问你在(B,C)之间的数有多少个. 题解:对于每个数判断一下就好了嘛 x,y,z = map(int,input().split()) n = int(input()) print(len(list(filter(lambda x:y<int(x) and z>int(x),input().split())))) B. Cutting Carrot 题意:给你一个高为h,底为1的等腰三角形,你需要平…
这次的前三题挺简单的,可是我做的不快也不对. A. Bank Robbery time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open…
第二弹: 套路&&经验总结: 1. N堆***的游戏,一般可以打表找SG函数的规律.比如CodeForces 603C 2.看起来是单轮的游戏,实际上可能拆分成一些独立的子游戏.比如CodeForces 317D 3.考虑最终如果某方胜利,最后的局面会是怎样. 比如CodeForces 594A 4.大力分类讨论,不要怕麻烦,在纸上写清楚. 比如 CodeForces 455B CodeForces 794C 题目大意: A和B各有一个大小为N的可重复字符集合,然后两个人轮流,每次取出从自…
传送门 D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when you have to make a hard decision — to rest…
B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/B Description Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend wi…
题目链接:https://codeforces.com/contest/1090/problem/A A conglomerate consists of n companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to s…
E. MST Company time limit per test 8 seconds memory limit per test 256 megabytes input standard input output standard output The MST (Meaningless State Team) company won another tender for an important state reform in Berland. There are n cities in B…
E - Company 思路: 首先,求出每个点的dfs序 然后求一些点的公共lca, 就是求lca(u, v), 其中u是dfs序最大的点, v是dfs序最小的大点 证明: 假设o是这些点的公共lca, in[o]是o的入时间戳, out[o]是o的出时间戳, 那么对于任意一点x, in[o] <= in[v] <= in[x] <= in[u] <= out[o] 所以o是x的祖先 所以o是这些点的公共lca 所以只要求出每段区间的dfs序最大的和最小的, 删除的要么是最大的,…
https://codeforces.com/contest/1062/problem/E 题意 给一颗树n,然后q个询问,询问编号l~r的点,假设可以删除一个点,使得他们的最近公共祖先深度最大.每次询问,输出删除的点和祖先的深度 思路 考虑dfs序来判断v是否在u的子树里: dfn[u]<dfn[v]<=max(dfn[u的子树]) 那么进一步拓展,dfs序之差越大,点就在越分离的地方,这些点的lca一定是lca(max(dfn[u]),min(dfn[u])) 这不仅知道了需要去掉哪个点(…
Description The company \(X\) has \(n\) employees numbered from \(1\) through \(n\). Each employee \(u\) has a direct boss \(p_u\) \((1 \le p_u \le n)\), except for the employee \(1\) who has no boss. It is guaranteed, that values \(p_i\) form a tree…
http://codeforces.com/problemset/problem/580/B 题意:Kefa有n个朋友,要和这n个朋友中的一些出去,这些朋友有一些钱,并且和Kefa有一定的友谊值,要求这些朋友间的贫富差距(拥有的钱的数量)小于d,要求Kefa邀请出来的朋友的友谊值和最大,并输出这个最大值. #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm&g…
[题目]C. Bear and Company [题意]给定大写字母字符串,交换相邻字符代价为1,求最小代价使得字符串不含"VK"子串.n<=75. [算法]动态规划 [题解]关键在于表示状态,我们将确定下来的前若干个固定作为状态,后面新加的字符不会进入固定的前若干个.(为了方便,非'V''K'的字符皆为‘X') 由于相同字符显然不可能跨越,那么前若干个的有效信息只有:它是由前v个’V',前k个‘K',前x个’X'组成的,最后一个字符是否’V',即f[v][k][x][0/1].…
题意与分析(CodeForces 580B) \(n\)个人,告诉你\(n\)个人的工资,每个人还有一个权值.现在从这n个人中选出m个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的工资不能超过他的工资+d. 这题用尺取法可以漂亮的解决.尺取法按照<挑战>一书的定义,是"指对数组保存一对下标(起点和终点),然后根据实际情况交替推进两个端点直到得到答案"的一种方法,因为这种操作"很像是尺蠖(日文中称为尺取虫)爬行的方式"而得名. 具体到这…
题目链接: D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when you have to make a hard decision — to re…
原题链接:http://codeforces.com/contest/580/problem/B 题意: 给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大m的差不超过d的情况下,s的和的最大值. 题解: 先排序,然后对于a[i],直接二分a[i].s+d的位置,然后维护一个前缀和,更新答案即可. 代码: #include<iostream> #include<cstring> #include<algorithm> #inc…
Restructuring Company Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, discard and merge departments, fire employees and do other unpleasant stuff. Let's consider the following mo…
->链接在此<- B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n fri…
Description 一开始有 \(n\) 个元素,可以进行几个操作. 合并 \(x,y\) . 合并 \(x,x+1,...,y\) . 询问 \(x,y\) 是否在一个集合中. Sol 并查集+链表. 第二个询问,一直用链表找 \(pre\) 优化一下就可以了. 另外 51Nod 1525 重组公司. Code #include<cstdio> #include<utility> #include<algorithm> #include<iostream&g…
题意:给定一个带权边无向图,求最小生成树,且满足第一个节点的度为固定的k 无解则输出-1 数据规模: 节点数n和限制k<=5000 边数m<=10^5 时限8sec 思路: 首先时限比较宽,第一个想到的暴力做法是枚举第一个节点(即首都)选中的K条边,复杂度为阶乘级别 无法接受.但是我们可以确定,问题的关键在于在所有国道中选择哪k条国道.一旦k条国道选定,最小生成树就是固定的. 考虑一个极端的情况,如果我们直接对这个图运行Kruskal算法,得到了一个树 且 第一个节点的度为k,则这就是正确的答…
题意:给定 3 种操作, 第一种 1 u v 把 u 和 v 合并 第二种 2 l r 把 l - r 这一段区间合并 第三种 3 u v 判断 u 和 v 是不是在同一集合中. 析:很容易知道是用并查集来做,但是如果单纯的用并查集,肯定是要超时的,所以要用链表,如果合并了,就把链表指向, 这样就搞定了这个题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i…
排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typedef long long ll; //#define LOCAL ; struct Node { int m,s; void IN(){ scanf("%d%d",&m,&s); } bool operator < (const Node&rh) const {…