codeforces 357C Knight Tournament(set)】的更多相关文章

Knight Tournament Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple pea…
Description Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant.…
http://codeforces.com/problemset/problem/356/A 首先理解题意 每次给出l 和r  在l - r之间还有资格的选手中得出一个胜者 暴力思路: 首先维护还有资格的选手的集合 用一个数组 表示 这个选手被谁击败 每次遍历 l - r 然后把不是胜者 且 还在集合中的选手踢出 并更新这个选手的数组值 最终 输出这个数组即可 这样会TLE 1. 如果用数组维护这个集合的话 每次遍历都是这样就是O(n^2) -->> 所以用set维护这个集合 2.使用set后…
 Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights…
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There's no s…
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There's no s…
Problem description Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple p…
题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所击败了(l<=x<=r),被击败的人立马退出游戏让你最后输出每个人是被谁击败的,最后那个胜利者没被 人击败就输出0 思路:他的每次修改的是一个区间的被击败的人,他而且只会记录第一次那个被击败的人,用线段树堕落标记的话他会记录最后一次的,所以我们倒着来修改, 然后因为那个区间里面还包含了自己,在线段…
脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> #include <set> using namespace std; ]; set<int>se; set<int>::iterator it1,it,it2; int main() { int i,x,y,num,n,m; scanf("%d%d"…
[链接] 我是链接,点我呀:) [题意] n个人矩形m场比赛 每场比赛由编号为li~ri且之前没有被淘汰的人进行. 已知第i场的winner是xi winner会把这一场其他所有的人都淘汰. 问你n个人每个人都是被谁给淘汰的. [题解] 并查集 初始条件f[i] = i,nex[i] = i + 1; 每一轮战斗,让输的人的f[find_father(i)]变成x[i] 但是在执行f[find_father(i)]=x[i]的时候 我们要记录一下ans[find_father(i)] = x[i…
Codeforces Round #207 (Div. 1) A:http://codeforces.com/problemset/problem/356/A 题意:给你n匹马,然后有m场比赛.每场比赛有一个l,r,x,表示编号从l,r之间的马都被x给打败了,但是这里如果之前已经败了,那么这里的区间就不会包括了. 题解:题解,直接用一个set搞定. 思维过程:首先,想到,对于一场比赛来说,如果之前已经败了的话,这里就不用在考虑了,但是如何判断这个区间里面的马已经败了,朴素的想法,就是查询还是在这…
http://codeforces.com/contest/357/problem/C #include <cstdio> #include <cstring> #include <algorithm> #define maxn 300010 using namespace std; int n,m; int l1,r1,x1; struct node { int l,r; int cover; }tree[maxn*]; int x[maxn]; void build…
在第8组数据上WA了一天,后来才发现问题: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 200009 #define inf 1e15 using namespace std; int n,k,q; struct node { int score; int pain; bool operator<(const node &a…
题面传送门 本蒟蒻想练习一下并查集,所以是找并查集标签来这里的.写题解加深理解. 解决思路 自然,看到区间修改之类很容易想到线段树,但本蒟蒻线段树会写挂,所以这里就讲比较简单的并查集思路. 并查集的核心是 \(\text{find}\) 函数.\(\text{find}\) 函数的目的是找到一个节点的父亲,本题中用于快速地找到下一个点搜谁.不带权的 \(\text{find}\) 很好理解也很好写.如果父亲是本身,直接返回即可.否则去找父亲的父亲,并更新.一般这样写: int find(int…
A. Group of Students time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output At the beginning of the school year Berland State University starts two city school programming groups, for beginners an…
A. Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knight…
收录已发布的题解 按发布时间排序. 部分可能与我的其他文章有重复捏 qwq . AtCoder for Chinese: Link ZHOJ: Link 洛谷 \(1\sim 5\) : [题解]CF45I TCMCF+++ [题解]CF1013B And [题解]CF991C Candies [题解]CF356A Knight Tournament [题解]CF1715A Crossmarket \(6\sim 10\) : [题解]CF1215C Swap Letters [题解]CF172…
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who wil…
A. Tennis Tournament 题目连接: http://www.codeforces.com/contest/628/problem/A Description A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tourname…
Codeforces 678E. Another Sith Tournament 题意: n(n<=18)个人打擂台赛,给定任意两人对决的胜负概率,比赛规则:可指定一人作为最开始的擂主,每次可指定台下的人替代失败的人上去对决,失败的人出局.问在最优决策下,第一个人留到最后的概率. 思路: 首先要观察到这一性质:一号玩家要想取得最终胜利的概率尽可能大,一定要把他安排在最后上场,只打一次.获胜概率与当前擂主以及台下的人有关,所以这个是状态,容易想到需要用二进制表示来压缩状态. 然而想到这些还是不好做…
A. Tennis Tournament time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners mo…
题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard output 问题描述 The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tour…
[题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之j赢i),连边从赢者向输者,从而得到一个有向完全图. 2.对于其中点数>1的强连通分量再次进行过程1,直至不存在点数>1的强连通分量为止. 给定n和p,求游戏总场次的期望.2<=n<=2000. [算法]数学概率,期望DP [题解]答案只和点数有关,设ans(n)表示n个点游戏总场次的…
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only t…
Discription Farmer John is hosting a tennis tournament with his n cows. Each cow has a skill level si, and no two cows having the same skill level. Every cow plays every other cow exactly once in the tournament, and each cow beats every cow with skil…
奉上官方题解 然后直接写的记忆化搜索 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <queue> #include <algorithm> #include <cstring> using namespace std;…
题解: 思路挺简单 但这个set的应用好厉害啊.. 我们把它看成图,如果a存在一门比b大,那么a就可以打败b,a——>b连边 然后求强联通分量之后最后顶层的强联通分量就是能赢的 但是因为是要动态维护,所以你每次都tarjan就炸了 我们考虑用set维护 我们将比较运算符定义为只要存在元素a>b或者b>a就是等于 然后我们就可以暴力合并等于的联通快 用set维护就可以了…
题意 一个竞赛图的度数集合是由该竞赛图中每个点的出度所构成的集合. 现给定一个 \(m\) 个元素的集合,第 \(i\) 个元素是 \(a_i\) .(此处集合已经去重) 判断其是否是一个竞赛图的度数集合,如果是,找到点数最小的满足条件的竞赛图,并构造方案. \(m, a_i \le 30\) ,\(a_i\) 互不相同. 题解 首先给出结论:假如给出每个点的出度,那么这些点能形成一个竞赛图当且仅当排序后的序列 \(d_1, d_2, d_3, \dots , d_n\) 满足对于所有 \(k…
题目链接:传送门 题目大意:有n个人决斗(n<=18),每两个人之间都有一定几率杀死对方,一次进行一次决斗,胜利者成为擂主继续接受决斗直到只剩下一个人,你是一号,问你最大有多大几率存活到最后. 题目思路:看到n<=18一般都能想到状态压缩DP,但是当时并没有想到怎么转移状态,下来补题发现了一个好博客讲的很详细 传送门 最后自己理解完后也讲一讲大致的思路首先一个二维DP数组 dp[1<<n|1][n]  一维的二进制数代表哪些人存活,二维代表当前第几号为擂主,而这道题关键就是要倒着D…
题意: 有\(n(n \leq 18)\)个人打擂台赛,编号从\(1\)到\(n\),主角是\(1\)号. 一开始主角先选一个擂主,和一个打擂的人. 两个人之中胜的人留下来当擂主等主角决定下一个人打擂,败的人退出比赛,直到比赛只剩一个人. 已知任意两人之间决胜的胜率\(P_{ij}\),求主角最终能够获胜的概率. 分析: 设\(d(S, i)\)表示存活的人的集合为\(S\),当前擂主为\(i \in S\),主角获胜的概率. 为了方便我们把编号设为\(0 \sim n-1\),递推边界\(d(…