codefroces 650A. Watchmen】的更多相关文章

A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. The…
传送门 time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n…
题意:两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离 也就是:x1=x2或y1=y2,再删除重合点造成的重复计数即可. #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <ma…
http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y_j$ ,假如无重复的话就是分别记录 $x$ 和 $y$ 的值然后 $ans+=mx[i]-1,ans+=my[i]-1$ ,就可以了. 那么有重复的话,有两种解决方法,第一种是分类讨论,就是分重复点和同 $x$ 其他点连.重复点和同 $y$ 其他点连.重复点自己连. #include<bits/s…
Watchmen CodeForces - 650A Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arra…
650A Watchmen 637A Voting for Photos 点击查看原题 650A又是一个排序去重的问题,一定要注意数据范围用long long ,而且在写计算组合函数的时候注意也要用long long 虽然10^9没有超过long的范围,但是在计算n*(n-1)/2的过程中超了,所以需要用long long ,否则会出错. #include<iostream> #include<cmath> #include<cstdlib> #include<c…
最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------只建立源文件无法调试,需要建立一个工程后才能调试 3.设置断点后,调试不会停止------开启-g模式且工程要建立在一个没有中文名的文件夹下 4.调试中如何查看变量------打开debug中的watch,右键编辑界面的变量可以选择添加变量 水题来源---codeforces(hzwer神犇刷的水题…
A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. The…
A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. The…
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan, but there are s…
Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |yi| ≤ 109) 思路:开始想的是容斥原理,即按x,y分别排序,先计算同x的点,然后在计算同y的点,这时由于相同的点之间的连边已经算过了,这样就不能再算.并且同一个y的点中可以每个点有多个点,算是不好编码的(反正我敲了很久..WA了) 反思:上面的容斥原理是从总体的思路来考虑的,这道题的难点也就是…
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan, but there are s…
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. The…
C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watch…
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. The…
题目链接:https://vjudge.net/contest/237394#problem/C Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, …
Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划,但是确发现了一些问题很难解决.马医生从第i个表匠到第j个表匠所需要的时间为|xi - xj| + |yi - yj|.然而蛋蛋所需要的时间为 要想成功完成任务,必须保证两人从第i个表匠出发,同时到达第j个表匠.现在请你计算最多有多少组表匠的位置满足条件 Input 第一行只有一个数n( 1 ≤ n…
目录 CF650A Watchmen 1. 手推公式 2.算法 3.优化 4.补充 CF650A Watchmen 只有三个map的一篇题解 1. 手推公式 \(|x2-x1|+|y2-y1|=\sqrt{(x2-x1)^2+(y2-y1)^2}\) 设|x2-x1|=a,|y2-y1|=b \(a+b=\sqrt{a^2+b^2}\) \((a+b)^2=a^2+b^2\) \(a^2+2ab+b^2=a^2+b^2\) \(2ab=0\) \(ab=0\) \(|x2-x1|*|y2-y1|…
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan, but there are s…
Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距离为1 题解 由于是从根出发的路径,所以 距离这条路径的距离为1=这个点的父亲在路径上 本身就在根出发的这条路径上,当然这个点的父亲也在路径上 这样我们就把两个条件统一了,转化问题为: 是否存在一条从根出发的路径,使所有点都在这条路径上 根据从根出发的路径的特点,我们根据深度,从小到大排序,每次看后…
http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 30, t = 5,所以最多推进150格.范围很小,开一个300*300的数组,初始位置在(150, 150),直接BFS. #include <cstdio> #include <algorithm> #include <iostream> #include <cst…
http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打.div1 >= 1900,div2 < 1900.求打完这n场比赛后可能得到的最大分数.如果无限大就输出"Inifinity",如果有矛盾就输出"Impossible". 思路:官方题解. For every contest we know that th…
time limit per testsecondsmemory limit per testmegabytesinputstandard inputoutputstandard outputPolycarp has quite recently learned about email aliases. Of course, he used to suspect that the case of the letters doesn't matter in email addresses. He…
http://codeforces.com/gym/100781/attachments 题意:有N个点,M条边,问对两两之间的树添加一条边之后,让整棵大树最远的点对之间的距离最近,问这个最近距离是多少. 思路:一开始看成只有两个连通块,后来才注意到是多个连通块.DFS搜树上最长路径.答案有三种:第一种是添加了边之后,树的最长路径还是原来子树的路径,第二种是对子树长度进行排序后,两个最长的距离分别除以2向上取整后加上1.第三种比较难注意到,就是第二第三长的分别除以2向上取整后加上2,因为可能隔着…
题意翻译 给出一个数列,有q个操作,每种操作是把区间[l,r]中等于x的数改成y.输出q步操作完的数列. 输入输出格式 输入格式: The first line contains one integer n n n ( 1<=n<=200000 1<=n<=200000 1<=n<=200000 ) — the size of array a a a . The second line contains n n n integers a1 a_{1} a1​ , a2…
problem:一个圆上依次有1~2*n的数字.每个数字都有且只有另一个数字与他相连.选出三条线,使得每条线的两端之间隔的最少点(只包括被选择的6个点)的个数相等.输入输出格式输入格式: The first line contains integer n(3<=n<=10^5) — the number of lines. Each of the following n n n lines contains two integers ai​,bi​ (1<=ai,bi<=2n),…
Description两个人Van♂游戏.给出$n$个正整数$ai$两人轮流操作,每次选出一个素数$p$和一个幂数$k$,选择的前提为该$n$个数中有$p^{k}$的倍数.接着将所有的$p^{k}$的倍数除以$p^{k}$.变成新的序列,继续操作.不能操作者为败,问先手是否必胜.1≤100≤n,1≤ai≤109ExamplesInput41 1 1 1OutputArpa Input41 1 17 17OutputMojtaba Input41 1 17 289OutputArpa Input5…
Description给你一个长度为$n$的序列$A$.现在准许你删除任意一个数,删除之后需要修改最小的次数使序列单调递增.问最小次数.$1≤n≤200000$ExamplesInput55 4 3 2 1Output3Input51 2 8 9 5Output0 因为是修改形成递增,所以假设修改$l+1~r-1$,那么要求$a[r]-a[l]-1>=r-l-1$ 于是有$a[r]-r>=a[l]-l$ 于是就转化为求最长不下降子序列 因为可以删一个点,删掉的点的后面的值减去的位权-1 设$f…
Description定义$F(x)$为$F(x−1)$与$F(x−2)$的连接(其中$F(0)="0"$,$F(1)="1"$)给出一个长度为$n$的$01$字符串$s$,询问$s$在$F(x)$的所有子序列中出现了多少次.$1≤n≤100$$0≤x≤100$ExamplesInput2 411Output14Input10 1001010101010Output553403224 $f[i][l][r]$表示有多少$F[i]$的子序列里包含字符串[l,r] 有3…
A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. F…