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的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. [Codeforces #514] Tutorial

    Link: Codeforces #514 传送门 很简单的一场比赛打崩了也是菜得令人无话可说…… D: 一眼二分,发现对于固定的半径和点,能包含该点的圆的圆心一定在一个区间内,求出区间判断即可 此题 ...

  7. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  8. CodeForces Round #514 (div2)

    A:Cashier 题意:问可以休息多少次. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen( ...

  9. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  10. Codeforces 514 D R2D2 and Droid Army(Trie树)

    题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define ...

随机推荐

  1. c++浅拷贝和深拷贝---14

    原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 1.什么是拷贝构造函数: 拷贝构造函数,又称复制构造函数,是一种特殊的构造函数,它由编译器调用来 ...

  2. 数据注解特性--NotMapped

    NotMapped特性可以应用到领域类的属性中,Code-First默认的约定,是为所有带有get,和set属性选择器的属性创建数据列.. NotManpped特性打破了这个约定,你可以使用NotMa ...

  3. PHP 免费获取手机号码归属地

    一.淘宝网API API地址: http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443 参数: tel:手机号码 返回 ...

  4. Ognl_JSTL_学习笔记

    控制标签 使用Struts2标签必须先导入标签库,在页面使用如下代码导入Struts2标签:<%@taglib prefix="s" uri="/struts-ta ...

  5. 8 -- 深入使用Spring -- 1...两种后处理器

    8.1 两种后处理器 Spring框架提供了很好的扩展性,出了可以与各种第三方框架良好整合外,其IoC容器也允许开发者进行扩展,这种扩展甚至无须实现BeanFactor或ApplicationCont ...

  6. NetBpm XML解读(5)

    原文: nPdl的翻译 在看NetBPM的nPdl文档时做了个翻译,一来是让自己能更好的理解nPdl,二来是希望能得到关心NetBPM的同志的指导.    由于对工作流不熟悉,所以有不少术语翻译没有把 ...

  7. Maven发布war包到Tomcat

    一.修改Tomcat下配置文件tomcat-users.xml,然后启动 <role rolename="manager-gui"/> <role rolenam ...

  8. 深入浅出MFC——MFC程序的生死因果(三)

    1. 本章主要目的:从MFC程序代码中检验出一个Windows程序原本该有的程序进入点(WinMain).窗口类注册(RegisterClass).窗口产生(CreateWindow).消息循环(Me ...

  9. css媒体查询来书写二倍图三倍图设置

    @media (-webkit-min-device-pixel-ratio: 2){} @media (-webkit-min-device-pixel-ratio: 3){}

  10. mysql学习笔记(三)

    -- 主键冲突(duplicate key) ,'xujian','anhui'); ,'xiewei','anhui'); ,'luyang','anhui');-- 主键冲突了 -- 可以选择性的 ...