[Codeforces] 347B - Fixed Points】的更多相关文章

题意:给定一个序列,现有一种操作:两个数的位置互换.问最多操作一次.序列 [元素位置i]  与 [元素Ai] 相等的最多个数? 依据题意,最多个数为 : [操作之前[元素位置i]  与 [元素Ai] 相等的个数] +  [调换两个 [元素位置i]  与 [元素Ai] 不相等 的元素 使某个 [元素位置i]  与 [元素Ai] 相等的个数]. 举个样例: 0 1 2 4 3 这个序列,调换后面两个元素,正好使每一个 [元素位置i]  与 [元素Ai] 相等. 也就是说,调换的时候,不用考虑 [元素…
题意:给定 n 数,让你交换最多1次,求满足 ai = i的元素个数. 析:很简单么,只要暴力一遍就OK了,先把符合的扫出来,然后再想,最多只能交换一次,也就是说最多也就是加两个,然后一个的判,注意数组越界. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <cstring> using namespace st…
link:http://codeforces.com/contest/347/problem/B 很简单,最多只能交换一次,也就是说,最多会增加两个.可能会增加一个.也可能一个也不增加(此时都是fixed point) #include <cstdio> using namespace std; ]; int main(void) { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif i…
题目链接:http://codeforces.com/problemset/problem/347/B 题目意思:给出一个包含n个数的排列a,在排列a中最多只能作一次交换,使得ai = i 这样的匹配达到最多. 作一次交换,最理想的情况是,在原来匹配好的序列中再匹配到两个数:最坏的情况是,即使作怎样的交换,都不可能再找到可以匹配的两个数,也就是说,根本不需要作交换.至于一般情况下,是可以再匹配到一个数的. 我是设了两个数组(分别有n个数):a(用来存储待判断的序列a)和b(依次存储0-n-1个数…
B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For ex…
D. Points Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D Description Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (…
题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points wi…
http://codeforces.com/contest/347/problem/B #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n; ]; ]; int main() { while(scanf("%d",&n)!=EOF) { ; ; i<n; i++) { scanf("%d",&…
题目链接:http://codeforces.com/contest/19/problem/D 题意:给出3种操作:1)添加点(x,y),2)删除点(x,y),3)查询离(x,y)最近的右上方的点. 且满足添加的点不重复,删除的点一定存在. 题解:只要以x建树,记录下每个结点最大的y值.每次都更新一下.用线段树查找满足条件的最小的x,然后用一个set[x]来存x点下的y点. 然后用二分查找满足条件的最小的y. #include <iostream> #include <cstring&g…
题目描述: Match Points time limit per test 2 seconds memory limit per test 256 mega bytes input standard input output standard output You are given a set of points x1, , ..., *x**n* Two points iand jcan be matched with each other if the following conditi…
题 OvO http://codeforces.com/contest/871/problem/C ( Codeforces Round #440 (Div. 1, based on Technocup 2018 Elimination Round 2) - C ) 解 问题可以转化为:这些点可以产生的横线与竖线的出现情况 首先,对于二维坐标系中的每一行中,对于每个点,如果右边有点,则从该点向右边这个点(相邻的那个点)连一条边(连一条单向的), 对于每一列中,对于每个点,如果该点下面有点,则向下…
题目链接 根据题意,d是两个点的最短距离,分析知,假设\(x_i\)<\(x_j\), 若\(v_i\)>\(v_j\),那么d(i,j)一定为0,因为i一定能追上j,否则,d(i,j)就为其初始距离 那我们就转化问题为一个二维偏序问题,求\(x_i\)<\(x_j\)且\(v_i\)<\(v_j\),满足这个条件的每个点对之间的距离 很容易想到定一序,另一序用树状数组维护的统计法,假设现在是\(x_i\),满足上述条件有k个,那么,对\(x_i\)的统计答案为:\(\sum_{j…
https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖问题,第一反应树状数组.线段树,看了看数据规模,开不了这么大的空间. 只能用差分了  代码如下: #include <stdio.h> #include <string.h> #include <iostream> #include <string> #incl…
B. Cover Points time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output There are n points on the plane, (x1,y1),(x2,y2),-,(xn,yn). You need to place an isosceles triangle with two sides on the coordin…
Codeforces 题目传送门 & 洛谷题目传送门 显然,直接暴力枚举是不可能的. 考虑将点按横纵坐标奇偶性分组,记 \(S_{i,j}=\{t|x_t\equiv i\pmod{2},y_t\equiv j\pmod{2}\}(i,j\in[0,1])\),说白了就是横坐标为偶数.纵坐标为偶数:横坐标为偶数.纵坐标为奇数:横坐标为奇数.纵坐标为偶数:横坐标为奇数.纵坐标为奇数的点集. 然后考虑以下算法: 若 \(S_{0,0},S_{1,1}\) 以及 \(S_{0,1},S_{1,0}\)…
题意:给出n个点,m个区间,需要给这些点涂上蓝色或者红色,使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1 唉,题目的标题就标注了一个easy= = 最开始做的时候对点还有区间都排序了,模拟来做,可是错了 后来发现不管区间怎么样,只要红色和蓝色交替涂色, 就一定能满足“使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1 ”这个条件 有点像上次做的cf交替输出奇数偶数那个A题 #include<iostream> #include<cstdio> #in…
我的方式是用暴力的方法找到每一行每一列的边界点: 但是有大神直接用一个公式解决了:floor(n*sqrt(2))*4: 想了很久还是不理解,求各路大神指点! #include<iostream> #include<cmath> #include<cstring> using namespace std; int main() { long long n; cin>>n; ){cout<<;;} ,cur; ; ;i<=n;i++) { c…
<题目链接> <转载于 >>>  > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GCD可求的某条给定线段上有多少个整数点,理由如下: GCD(n,m)为n与m的最大公约数,通过辗转相除法求得.令g=GCD(n,m); n=x*g, m=y*g.所以将横坐标分为g个x份,将纵坐标分为g个y份.所以,本题线段覆盖的整数点个数为 g+1 (因为包含端点,如果不包含端点就为 g-1 ). 但是这样求…
题解: 暴力,模拟. 把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可. #include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; char s[maxn]; struct X { char id; int num; }p[maxn], q[maxn]; int sz; void work() { for(int i = 0; i <= sz; i ++) { if(i == 0 ||…
又一次写起了几何.... 特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个set里,对每一个set,每次删除set.size()即可 重点在于判断两条线段的交点是否是一个整数点,需要特殊考虑,平行和y=kx+b关系式不能成立的情况 我的代码中没有判断除数为0的情况(因为不会报错,我也就没写23333,但不影响结果 #include<iostream> #include<cstdio> #include<cmath> #in…
[链接] 我是链接,点我呀:) [题意] 让你从一个集合中找出来一个子集 使得这个子集中任意两个数相减的绝对值是2^的整数次幂 且集合的大小最大 [题解] 考虑子集的个数为4个或4个以上 那么我们找到最小的4个a[1],a[2],a[3],a[4] 显然 dis(1,2)=2^a dis(2,3)=2^b dis(1,3)=dis(1,2)+dis(2,3) = 2^c 因为2^a+2^b=2^c 所以可以推出来a=b 也即dis(1,2)=dis(2,3) 同理对于a[2],a[3],a[4]…
题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为前闭后开,同时在求总点数的时候,也按前闭后开的区间来求,这样就巧妙避开了两个端点之间的讨论,只用维护好一个端点就行了. 代码比文字更容易理解: 1 #include <bits/stdc++.h> 2 #define lowbit(x) x&-x; 3 typedef long long…
题目链接:http://codeforces.com/contest/340/problem/E E. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub is so happy about inventing bubble sort graphs that he's sta…
C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permu…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Iahub and Permutations Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more import…
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个数组各至少一个数. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n, m; ], b[]; int main() { , y = , s = ; scanf(…
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51735818 在数学中,函数的不动点(Fixed point, or shortened to fixpoint, also knowns as invariant point),指的是在函数定义域内的某一个值,经过函数映射后的值还是其本身. 也就是说如果 c 是函数 f(c) 的不动点,则有: 由上面很容易进行递归推导: 满足这样经过…
B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For ex…
Fixed Points CodeForces - 347B A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are n…
转自:http://blog.evjang.com/2017/01/nips2016.html           Eric Jang Technology, A.I., Careers               Monday, January 2, 2017 Summary of NIPS 2016   The 30th annual Neural Information Processing Systems (NIPS) conference took place in Barcelona…