Codeforces #614 div.2 (A-E)
A ConneR and the A.R.C. Markland-N
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++) int t, n, s, k, x; int main() {
cin >> t;
while (t--) {
cin >> n >> s >> k;
map<int, int> m;
inc(i, , k) {
cin >> x;
m[x] = ;
}
inc(del, , k) {
if ((s + del <= n && m[s + del] == ) ||
(s - del >= && m[s - del] == )) {
cout << del << "\n";
break;
}
}
}
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++) int n;
double r; int main() {
cin >> n;
for (int i = n; i >= ; i--) r += 1.0 / i;
printf("%.12f", r);
}
每个岩浆点的对面或斜对面如果也有岩浆点,那么这两点之间就会形成障碍,统计这种障碍的数量
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++) const int maxn = 1e6 + ; int a[][maxn];
int n, q, k, x, y; int main() {
cin >> n >> q;
inc(i, , q - ) {
cin >> x >> y;
x--;
if (a[x][y] == ) {
a[x][y] = ;
inc(del, -, ) if (a[ - x][y + del] == ) k++;
} else {
a[x][y] = ;
inc(del, -, ) if (a[ - x][y + del] == ) k--;
}
if(k) puts("NO");
else puts("YES");
}
}
分析点集的特点,可以知道每一个数据点都在下标比它小的数据点的右上方,而且离下一个数据点的距离 大于 离第0个数据点的距离。
枚举Aroma从哪个点出发;先往第0个数据点走,然后尽可能往右上走
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++) const int maxn = 1e6 + ; ll a0, b0, ax, bx, ay, by;
ll xs, ys, t; ll dx[maxn], dy[maxn];
ll dis[maxn]; int res; int main() {
cin >> a0 >> b0 >> ax >> ay >> bx >> by;
cin >> xs >> ys >> t;
ll tx = a0, ty = b0;
int top;
for (top = ; tx <= 2e16 && ty <= 2e16; top++) {
dx[top] = tx, dy[top] = ty;
tx = tx * ax + bx, ty = ty * ay + by;
}
inc(i, , top - ) dis[i] = dx[i] - dx[] + dy[i] - dy[];
inc(i, , top - ) {
ll tmp = t - abs(xs - dx[i]) - abs(ys - dy[i]);
if (tmp < ) continue;
int tot = ;
if (tmp <= dis[i]) {
tot = i - (lower_bound(dis, dis + top, dis[i] - tmp) - dis) + ;
} else {
tot = upper_bound(dis + i + , dis + top, tmp - dis[i]) - dis;
}
res = max(res, tot);
}
cout << res;
}
最大S的方案必然是0-L都在一条链上,这条链上的数字是“山谷”型
推出状态转移方程
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define pb push_back const int maxn = 3e3 + ;
vector<int> edge[maxn];
int n, u, v;
int sub[maxn][maxn], par[maxn][maxn];
ll dp[maxn][maxn], res; int root; int dfs(int x, int p) {
sub[root][x] = ;
for (int i = ; i < edge[x].size(); i++) {
if (edge[x][i] != p) {
par[root][edge[x][i]] = x;
sub[root][x] += dfs(edge[x][i], x);
}
}
return sub[root][x];
} ll solve(int u, int v) {
if (u == v) return ;
if (dp[u][v]) return dp[u][v];
return dp[u][v] = sub[u][v] * sub[v][u] +
max(solve(par[v][u], v), solve(par[u][v], u));
} int main() {
cin >> n;
inc(i, , n - ) {
cin >> u >> v;
edge[u].pb(v);
edge[v].pb(u);
}
inc(i, , n) {
root = i;
dfs(root, -);
}
inc(i, , n) inc(j, , n) {
res = max(res, solve(i, j));
}
printf("%lld\n", res);
}
Codeforces #614 div.2 (A-E)的更多相关文章
- Codeforces #344 Div.2
Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- codeforces #592(Div.2)
codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...
- codeforces #578(Div.2)
codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...
- codeforces #577(Div.2)
codeforces #577(Div.2) A Important Exam A class of students wrote a multiple-choice test. There are ...
- codeforces #332 div 2 D. Spongebob and Squares
http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...
- Codeforces Round #614 (Div. 2) C - NEKO's Maze Game
题目链接:http://codeforces.com/contest/1293/problem/C 题目:给定一个 2*n的地图,初始地图没有岩浆,都可以走, 给定q个询问,每个询问给定一个点(x,y ...
随机推荐
- py装饰器,生成器,迭代器
emmmmm....看了好久才能大概的看懂一点关于装饰器的内容...import sys # 引入sys模块import timeimport functoolsfrom functools impo ...
- 使用D3.js构建实时图形
首先你需要在计算机上安装Node和npm. 数据的可视化表示是传递复杂信息的最有效手段之一,D3.js提供了创建这些数据可视化的强大工具和灵活性. D3.js是一个JavaScript库,用于使用SV ...
- 《高性能javascript》阅读摘要
最近在阅读这本Nicholas C.Zakas(javascript高级程序设计作者)写的最佳实践.性能优化类的书.记录下主要知识. 加载和执行 脚本位置 放在<head>中的javasc ...
- 由一个项目需求引发的 - textarea中的换行和空格
当我们使用 textarea 在前台编辑文字,并用 js 提交到后台的时候,空格和换行是我们最需要考虑的问题.在textarea 里面,空格和换行会被保存为/s和/n,如果我们前台输入和前台显示的文字 ...
- SpringBoot内置的各种Starter是怎样构建的?--SpringBoot源码(六)
注:该源码分析对应SpringBoot版本为2.1.0.RELEASE 1 温故而知新 本篇接 外部配置属性值是如何被绑定到XxxProperties类属性上的?--SpringBoot源码(五) 温 ...
- Redis使用指南
原文链接 能坚持别人不能坚持的,才能拥有别人未曾拥有的.关注编程大道公众号,让我们一同坚持心中所想,一起成长!! 设置过期时间.释放资源 使用Redis做K-V存储,一定要注意过期时间的把控,任何K- ...
- MATLAB神经网络(7) RBF网络的回归——非线性函数回归的实现
7.1 案例背景 7.1.1 RBF神经网络概述 径向基函数是多维空间插值的传统技术,RBF神经网络属于前向神经网络类型,网络的结构与多层前向网络类似,是一种三层的前向网络.第一层为输入层,由信号源结 ...
- celery异步任务 定时任务
以前项目中用到过 celery ,但是没怎么记笔记,现在在记一下,方便以后用. Celery.png 问:Celery 是什么? 答:Celery 是一个由 Python 编写的简单.灵活.可靠的 ...
- Python模块一
logging模块 我们来说一下这个logging模块,这个模块的功能是记录我们软件的各种状态,你们现在和我一起找到红蜘蛛的那个图标,然后右键找一找是不是有个错误日志.其实每个软件都是有错误日志的,开 ...
- 【Python】2.11学习笔记 注释,print,input,数据类型,标识符
前面学了好多内存什么的知识,没什么用(我有眼不识泰山233 吐槽一句,这课简直就是讲给完全的编程小白听得 就从语言开始写吧(其实好多已经看过了,再来一遍 话说我已经忘了\(Markdown\)怎么写了 ...