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 ...
随机推荐
- Java面试必问之Hashmap底层实现原理(JDK1.7)
1. 前言 Hashmap可以说是Java面试必问的,一般的面试题会问: Hashmap有哪些特性? Hashmap底层实现原理(get\put\resize) Hashmap怎么解决hash冲突? ...
- js中的内置方法的兼容写法
1.如果浏览器不支持every属性,every的实现原理 if(Array.prototype.every===undefined){ Array.prototype.every=function(f ...
- Go coding in go way(用Go的思维去coding)
本文是Tony Bai在2017年第三届GopherChina大会上所作,来源如下 https://tonybai.com/2017/04/20/go-coding-in-go-way/ 一.序 今天 ...
- Android模拟器不能上网的解决方法
我原来一直不用Android的模拟器,因为这东西的多年前的印象真的是很糟糕——启动半个小时,不支持OpenGL.即使后来有了x86镜像,在HAXM的支持下快的飞起,也不想用,因为NDK还要编译x86的 ...
- php实现post跳转
大家否知道php可以利用header('Location')实现get请求跳转. php利用curl可以实现模拟post请求. 但是却找不到php现成的实现post跳转.那么问题来了,如果有这个需求该 ...
- mac笔记本编译go-ethereum报错CoreServices/CoreServices.h' file not found
查看xcode是否安装: $ xcode-select --install xcode-select: error: command line tools are already installed, ...
- 误用git reset -hard 的检讨书
误用git reset -hard 的检讨书 消失的代码们: 我知道你们可能看不到了,但是我还是需要自我反省自己,因为自己的误操作,导致了你们的消失. 事情的始末 夜阑人静,周围除了少年敲击键盘的声音 ...
- Java抽象类和接口的区别及联系
抽象类 注:先将抽象类中的两种方法解释完,再综合解释抽象类 抽象方法 应用场景:其下所有子类都应该有该方法但是大部分子类具体的执行步骤是有所不同的. 必须重写:也可以说"必须实现" ...
- Javascript十六种常用设计模式
单例模式 何为单例模式,就是无论执行多少次函数,都只会生成一个对象哈哈,看一个简单的demo function Instance(name) { this.name = name; } Instanc ...
- Spring Boot框架——快速入门
Spring Boot是Spring 全家桶非常重要的一个模块,通过 Spring Boot 可以快速搭建一个基于 Spring 的 Java 应用程序,Spring Boot 对常用的第三方库提供了 ...