codeforces#514 Div2---1059ABCD
1059A---Cashier
http://codeforces.com/contest/1059/problem/A
题意:
Vasya每天工作\(l\)个小时,每天服务\(n\)个顾客,每个休息时长是\(a\)。给定\(n\)个客人来的时间和时长。问Vasya可以休息多长时间。
思路:
先给客人排个序,然后各个间隔除以休息时间之和就是答案。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define N 100010
#define pi 3.1415926535 int n, l, a;
const int maxn = 1e5 + ;
struct node{
int l, len;
}peo[maxn];
bool cmp(node a, node b)
{
return a.l < b.l;
} int main()
{
while(scanf("%d%d%d", &n, &l, &a) != EOF){
for(int i = ; i < n; i++){
scanf("%d%d", &peo[i].l, &peo[i].len);
}
sort(peo, peo + n, cmp); int cnt = peo[].l / a;
for(int i = ; i < n; i++){
cnt += (peo[i].l - peo[i - ].l - peo[i - ].len) / a;
}
cnt += (l - peo[n - ].l - peo[n - ].len) / a;
printf("%d\n", cnt); }
return ;
}
1059B---Forgery
http://codeforces.com/contest/1059/problem/B
题意:
用笔可以填成下面这样。问能不能画出题目给定的样子。
xxx
x.x
xxx
思路:
每个\(.\)是的周围八个是不可以作为落笔的中心的。同时边界上的点也不可以作为边界中心。
而对于每一个\(#\),周围的八个中至少要有一个是可以作为中心的点。
卡了好久啊我的妈。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define N 100010
#define pi 3.1415926535 int n, m;
const int maxn = ;
char g[maxn][maxn];
char graph[maxn][maxn];
bool forbidden[maxn][maxn];
//int mvx[4] = {-1, 1, 0, 0};
//int mvy[4] = {0, 0, -1, 1}; bool inside(int i, int j)
{
return i >= && j >= && i <= n && j <= m;
} int main()
{
while(scanf("%d%d", &n, &m) != EOF){
memset(forbidden, , sizeof(forbidden));
for(int i = ; i <= n; i++){
scanf("%s", g[i] + );
for(int j = ; j <= m; j++){
//graph[i][j] = '.';
if(g[i][j] == '.'){
for(int dx = -; dx <= ; dx++){
for(int dy = -; dy <= ; dy++){
if(dx == && dy == || !inside(i + dx, j + dy))continue;
forbidden[i + dx][j + dy] = true;
}
}
}
}
} bool flag = true;
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
if(g[i][j] == '#'){
int cnt = ;
for(int dx = -; dx <= ; dx++){
for(int dy = -; dy <= ; dy++){
if(dy == && dx == || !inside(i + dx, j + dy))continue;
if(i + dx == || i + dx == n || j + dy == || j + dy == m)continue;
else if(!forbidden[i + dx][j + dy])cnt++;
}
}
if(cnt == ){
flag = false;
break;
}
}
}
if(!flag)break;
}
if(flag){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return ;
}
1059C---Sequence Transformation【递归】
http://codeforces.com/contest/1059/problem/C
题意:
给定一个\(1~n\)的序列,每一次求得这个序列中所有数的最小公因数,然后随机删掉一个。问怎样删可以使得得到的答案序列是字典序最大的。
思路:
因为给定的是\(1~n\)连续的整数,相邻两个数之间肯定是互质的。所以刚开始要去掉相邻的数,这部分的答案都是1
显然我们应该要尽量去掉奇数,因为要让字典序最大,就必须要让除1外的其他数尽快出现。删除奇数是最快的。
剩下来的数就是一堆偶数了。比如我们剩下了\(2,4,6,8\)。他们其实可以看成是\(1*2, 2*2, 3*2, 4*2\)
将他们除以\(2\)之后就又是一个\(1~4\)的子问题了。不断dfs递归下去,直到总数是1、2或3时就可以直接输出答案然后返回了。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define N 100010
#define pi 3.1415926535 int n; void dfs(int k, int mul)
{
if(k == ){
printf("%d ", mul);
return;
}
else if(k == ){
printf("%d %d ", mul, mul * );
return;
}
else if(k == ){
printf("%d %d %d ", mul, mul, mul * );
return;
} for(int i = ; i < (k + ) / ; i++){
printf("%d ", mul);
}
dfs(k / , mul * ); } int main()
{
while(scanf("%d", &n) != EOF){
dfs(n, );
printf("\n");
}
return ;
}
1059D---Nature Reserve【二分】【好题】
http://codeforces.com/contest/1059/problem/D
题意:
给定n个点,要求找到一个最小的圆覆盖这些点,并且这个圆和横坐标轴有且仅有一个交点。输出最小的半径。
思路:
刚开始想了很久的最小圆覆盖,还去学了一下模板。后来发现是不可以用最小圆覆盖的。因为最小圆覆盖得到的圆有可能和横坐标有两个交点。
正解应该是二分半径。
\(-1\)的情况很简单,只要有点在横坐标两侧或者横坐标上有多于两个点就不可以。
由于和横坐标轴有且仅有一个交点,所以半径一定就是圆心的纵坐标值。
二分半径,然后去看当前半径是不是可以包括所有的点。
这个要怎么判断呢。
假设点$p_{i}$的坐标为$(x_{i}, y_{i})$,当前的半径是$R$
那么圆心$c$的坐标就是$(x, R)$, 其中$x$是一个未知数。
圆心到$p_{i}$的距离要小于等于$R$,我们可以列出一个方程,
求出$x$的取值区间是$[x_{i} - \sqrt{R^{2} - (R-y_{i})^{2}}, x_{i} + \sqrt{R^{2} - (R-y_{i})^{2}}]$
如果$n$个点的这个区间的交集是空集的话,那么这个半径$R$就是不可行的。
输出搞了超级久,烦人。
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define N 100010
#define pi 3.1415926535 const int maxn = 1e5 + ;
const double eps = 1e-; int n;
struct node{
double x, y;
}p[maxn]; bool check(double x)
{
double l = -1e18, r = 1e18;
for(int i = ; i < n; i++){
if(p[i].y > * x)return ;
double t=sqrt(p[i].y*(*x-p[i].y));
l = max(l, p[i].x - t);
r = min(r, p[i].x + t);
}
return (l - r + eps) <= ;
} int main()
{
//ios_base::sync_with_stdio(false);
while(scanf("%d", &n) != EOF){
bool negative = false, positive = false;
int zero = ;
for(int i = ; i < n; i++){
cin>>p[i].x>>p[i].y;
if(p[i].y > )positive = true;
if(p[i].y < ){
negative = true;
p[i].y = -p[i].y;
}
if(p[i].y == )zero++;
} if(negative && positive || zero >= ){
printf("-1\n");
}
else{
double st = 0.0, ed = 1e18, ans;
for(int k = ; k < ; k++){
double mid = (st + ed) / ;
if(check(mid)){
ed = mid;
}
else{
st = mid;
}
}
//cout<<st<<endl;
printf("%f\n", st);//cout<<ans<<endl;
}
}
return ;
}
codeforces#514 Div2---1059ABCD的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- [Codeforces #514] Tutorial
Link: Codeforces #514 传送门 很简单的一场比赛打崩了也是菜得令人无话可说…… D: 一眼二分,发现对于固定的半径和点,能包含该点的圆的圆心一定在一个区间内,求出区间判断即可 此题 ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- CodeForces Round #514 (div2)
A:Cashier 题意:问可以休息多少次. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen( ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- Codeforces 514 D R2D2 and Droid Army(Trie树)
题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define ...
随机推荐
- ubuntu alsa
今天要在linux下搞音频编程,在网上查阅了一下资料,网上很多资料都是在linux下直接对/dev/dsp进行编程的,因为在以往的linux系统中,我们是可以通过cat xxx.wav /dev/d ...
- GoogLeNet解读
转载:http://blog.csdn.net/shuzfan/article/details/50738394 GoogLeNet主要贡献提出了Inception结构: Architectural ...
- InnoDB锁问题 & DB事务隔离级别
<参考:http://www.cnblogs.com/jack204/archive/2012/06/09/2542940.html>InnoDB行锁实现方式InnoDB行锁是通过给索引上 ...
- backbone学习笔记:模型(Model)(1)基础知识
backbone为复杂Javascript应用程序提供MVC(Model View Controller)框架,框架里最基本的是Model(模型),它用来处理数据,对数据进行验证,完成后台数据与前台数 ...
- mysql的wait_timeout配置(此处处理方法是有问题的,不建议作为操作参考)
mysql数据库有一个wait_timeout的配置,默认值为28800(即8小时). 在默认配置不改变的情况下,如果连续8小时内都没有访问数据库的操作,再次访问mysql数据库的时候,mysql数据 ...
- 【代码审计】iCMS_v7.0.7 keywords.admincp.php页面存在SQL注入漏洞分析
0x00 环境准备 iCMS官网:https://www.icmsdev.com 网站源码版本:iCMS-v7.0.7 程序源码下载:https://www.icmsdev.com/downloa ...
- Memcached 运行状态
memcached-tool 命令用于查看 Memcached 运行状态,用法如下: Usage: memcached-tool <host[:port] | /path/to/socket&g ...
- 用MyEclipse将Maven Dependencies中的jar包导出
1.右击pom.xml文件,选择Run As ——> Maven build… 2.在打开的页面中,如图输入“dependency:copy-dependencies”,后点击“Run”即可 ...
- 原:android4.2.2蓝牙源码阅读--bluedroid部分
概念: GKI:统一内核接口 BTE栈: BTU栈:BTU栈开始前必须调用BTE栈初始化 代码阅读: /external/bluetooth/bluedroid/hci/:HCI library实现 ...
- Google Analytics访问空白的解决方法
在C:\Windows \System32 \drivers \etc下用记事本打开hosts文档 添加: 74.125.129.112 adwords.google.com 74.125.31.12 ...