题目链接: B. Optimal Point on a Line 题意: 给出n个点,问找出一个点使得这个点到所有的点的距离和最小; 思路: 所有点排序后的中位数;这是一个结论; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #in…
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal. 输入 The first line contains integer n (1 ≤ n ≤ 3·105)…
题意 You are given n points on a line with their coordinates $x_i$. Find the point x so the sum of distances to the given points is minimal. 分析 答案是直觉上显然的:输出数组的中位数即可(对于偶数个数的,则是中间靠左).这样的结果正确的原因也很显然.首先,答案肯定在$[x_{min},x_{max}]$中,那么点无论在哪里,对于$x_i,x_{n-i}$这一对…
首先比较容易想到肯定是前k大的元素,那么我们可以先对其进行sort,如果数值一样返回下标小的(见题意),接下里处理的时候我们发现需要将一个元素下标插入到有序序列并且需要访问第几个元素是什么,那么我们可以离线处理,将所有询问存起来,每次插入一个元素的时候在对其进行查询,那么现在就变成了离线求第k大,那么可以直接上主席数,当然比较懒的做法就直接树状数组维护下标,二分查找答案. // ——By DD_BOND #include<bits/stdc++.h> #define fi first #def…
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file for some programming competition problem. His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually ge…
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R andx = a1k' + b1 = a2l' + b2, for some integers k', l' ≥ 0. 输入 Th…
C. Pie or die Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem/C Description Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbo…
A. King Moves water.= =. #include <cstdio> ,,,,,-,-,-}; ,-,,,-,,,-,}; #define judge(x,y) x >= 1 && x <= 8 && y >= 1 && y <= 8 int main() { char t; ; scanf("%c%d", &t, &y); x = t - ; ; i < ; i+…
Description You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line. The second li…
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why ev…
Optimal Point on a Line CodeForces - 710B You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of poi…
Shower Line CodeForces - 431B Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower…
The clock shows 11:30 PM. The sports programmers of the institute of maths and computer science have just finished their training. The exhausted students gloomily leave their computers. But there's something that cheers them up: Misha, the kind coach…
[未完待续] A The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and dis the row from '1' to '8'. Find the number of moves permitted for the king. King moves from the pos…
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) i…
2018-02-25 http://codeforces.com/contest/940/problem/A A. Points on the line time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We've got no test cases. A big olympiad is coming up. But the pr…
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that ea…
Happy Line Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 549G Description Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this…