A:Cashier

题意:问可以休息多少次。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int n, L, a;
int t[N], l[N];
int main(){
scanf("%d%d%d", &n, &L, &a);
for(int i = ; i <= n; ++i)
scanf("%d%d", &t[i], &l[i]);
t[n+] = L;
t[] = l[] = ;
int ans = ;
for(int i = ; i <= n; ++i){
int dif = t[i+] - t[i] - l[i];
ans += dif/a;
}
cout << ans << endl;
return ;
}

B:B - Forgery

题意:一次能给边上一圈填上'#',问这个图形合法不合法。填的时候不能越界。

直接去check行不行就好啦。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e3 + ;
char s[N][N];
int dx[] = {,,,,,,,};
int dy[] = {,,,,,,,};
int n, m;
bool in(int x, int y){
if(x < || x > n) return false;
if(y < || y > m) return false;
return true;
}
bool check2(int x, int y){
for(int i = ; i < ; ++i){
int xx = x + dx[i];
int yy = y + dy[i];
if(!in(xx,yy) || s[xx][yy] != '#') return false;
}
return true;
}
bool check(int x, int y){
for(int b = ; b < ; ++b){
if(check2(x-dx[b], y-dy[b])) return true;
}
return false;
}
int main(){ scanf("%d%d", &n, &m);
for(int i = ; i <= n; ++i) scanf("%s", s[i]+);
for(int i = ; i <= n; ++i)
for(int j = ; j <= m; ++j){
if(s[i][j] == '#'){
if(!check(i,j)){
puts("NO");
return ;
}
}
}
puts("YES");
return ;
}

C:C - Sequence Transformation

题意:给你[1,n]的数,每次会输出整个序列的gcd,然后可以删除一个数,然后问gcd的字典序排列最大是多少。

题解:发现 如果存在奇数,然后我们就会导致 gcd恒为1。 那么我们肯定是先删除奇数。

然后把奇数删完了之后,剩下了2,4,6,8,我们把这些数都/2,变成了新的1,2,3,4,然后再删除奇数就ok了。递归解决问题。

然后就是 如果出现了 1, 2, 3。 那么肯定是按照顺序删除 1 2 3最好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int n;
vector<int> vc;
void dfs(int k, int n){
if(n == ) return ;
if(n == ){
printf("%d %d %d", k, k, k*);
return ;
}
if(n == ){
printf("%d ", k);
return ;
}
if(n == ){
printf("%d %d", k, *k);
return ;
}
for(int i = ; i <= n; i += ){
printf("%d ", k);
}
dfs(k*, n/);
}
int main(){
scanf("%d", &n);
dfs(, n);
return ;
}

D:D - Nature Reserve

题意:有n个保护动物,然后就是让你画一个○,使得所有的动物都在圈内,并且只有1个交点。

不是很想多讲,二分乱搞就好了,注意精度。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
pll p[N];
int n, f1 = , f2 = ;
double eps = 1e-;
bool check2(double x1, double y1, double x2, double y2){
long double len = y2;
len *= len;
long double dis = (long double)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
return len >= dis;
}
bool check(double len){
double lp = -1e7, rp = 1e7;
for(int i = ; i <= ; ++i){
int lsz = , rsz = ;
double mid = (lp+rp) / ;
for(int k = ; k <= n; ++k){
if(check2(p[k].fi,p[k].se,mid,len));
else if(p[k].fi <= mid ) lsz++;
else rsz++;
}
if(lsz && rsz) return false;
if(lsz+rsz == ) return true;
if(lsz) rp = mid;
else lp = mid;
}
return false;
}
int main(){
scanf("%d", &n);
for(int i = ; i <= n; ++i){
scanf("%d%d", &p[i].fi, &p[i].se);
if(p[i].se > ) ++f1;
else ++f2, p[i].se = -p[i].se;
}
if(f1 && f2){
puts("-1");
return ;
}
double l = , r = 1e15;
for(int i = ; i <= ; ++i){
double mid = (l+r)/;
if(check(mid)) r = mid;
else l = mid;
}
printf("%.10f", r);
return ;
}

E:Split the Tree

题意:给定1棵以1为根的树,让你将这棵数分成竖着的几条链,问链最少是多少条,并且每一条链要求点的个数少于L,路径之和少于S。

题解:

从叶子网上爬,然后通过二分和倍增查看最多能到哪里,然后将这个点指到可以去的那个点为止。

然后不是叶子就接受叶子传上来的最远可以到哪里,如果到不了这个点就把这个点当做新的起点继续去找,如果可以到这个点就记录下最远可以去哪里就好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int anc[N][];
int a[N];
LL sum[N];
int n, l; LL S;
vector<int> vc[N];
int deep[N];
void dfs(int o){
for(int x : vc[o]){
deep[x] = deep[o] + ; sum[x] = sum[o] + a[x];
anc[x][] = o;
for(int i = ; i < ; ++i)
anc[x][i] = anc[anc[x][i-]][i-];
dfs(x);
}
}
int get(int o, int k){
for(int i = ; i >= ; --i){
if((k>>i)&) o = anc[o][i];
}
return o;
}
int to[N];
int ans;
int Find(int o){
int ll = , rr = l;
while(ll <= rr){
int mid = ll+rr >> ;
int p = get(o, mid);
if(sum[o]-sum[p] <= S) ll = mid+;
else rr = mid-;
}
return get(o, ll-);
}
void solve(int o){
to[o] = -;
for(int x : vc[o]){
solve(x);
if(to[x] == - || deep[to[x]] >= deep[o]) continue;
if(to[o] == -) to[o] = to[x];
else if(deep[to[o]] > deep[to[x]]) to[o] = to[x];
}
if(to[o] == -) ans++, to[o] = Find(o);
}
int main(){
scanf("%d%d%lld", &n, &l, &S);
for(int i = ; i <= n; ++i){
scanf("%d", &a[i]);
if(a[i] > S){
puts("-1");
return ;
}
}
for(int i = ,v; i <= n; ++i){
scanf("%d", &v);
vc[v].pb(i);
}
sum[] = a[]; deep[] = ;
dfs(); solve();
cout << ans << endl;
return ;
}

CodeForces Round #514 (div2)的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  4. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  5. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  6. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  7. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  8. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

  9. Codeforces Round #360 div2

    Problem_A(CodeForces 688A): 题意: 有d天, n个人.如果这n个人同时出现, 那么你就赢不了他们所有的人, 除此之外, 你可以赢他们所有到场的人. 到场人数为0也算赢. 现 ...

随机推荐

  1. 【Android】Genymotion 模拟器 Unable to create virtual device

    安装 Genymotion 模拟器的时候报了这个错误,如下: 后来找到了解决方法,见下图: 在 Setting -> Network, 勾选 Use HTTP Proxy, HTTP Proxy ...

  2. scroll-苹果滑动卡顿

    2018年08月02日,程序小bug. 在移动端html中经常出现横向/纵向滚动的效果,但是在iPhone中滚动速度很慢,感觉不流畅,有种卡卡的感觉,但是在安卓设备上没有这种感觉; 一行代码搞定: - ...

  3. codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题

    A.题意就是把字符串里面的数字按增序排列,直接上代码. #include <string.h> #include <stdio.h> #include <algorith ...

  4. Wpf窗口设置屏幕居中最前显示

    public Window()         {             InitializeComponent();             WindowStartupLocation = Win ...

  5. 分布式ID系列(3)——数据库自增ID机制适合做分布式ID吗

    数据库自增ID机制原理介绍 在分布式里面,数据库的自增ID机制的主要原理是:数据库自增ID和mysql数据库的replace_into()函数实现的.这里的replace数据库自增ID和mysql数据 ...

  6. 转载 | CSS图片下面产生间隙的 6种解决方案

    在进行页面的DIV+CSS排版时,遇到IE6(当然有时Firefox下也会偶遇)浏览器中的图片元素img下出现多余空白的问题绝对是常见的对於 该问题的解决方法也是「见机行事」,根据原因的不同要用不同的 ...

  7. thinkphp 框架两种模式 两种模式:开发调试模式、线上生产模式

    define(‘APP_DEBUG’,true/false);

  8. Springboot源码分析之项目结构

    Springboot源码分析之项目结构 摘要: 无论是从IDEA还是其他的SDS开发工具亦或是https://start.spring.io/ 进行解压,我们都会得到同样的一个pom.xml文件 4. ...

  9. Nacos(二):SpringCloud项目中接入Nacos作为注册中心

    前言 通过上一篇文章:Nacos介绍简单了解了Nacos的发展历程和现状,本文我们开始Nacos试水的第一步: 使用Nacos做注册中心 上周末(7.6)Nacos发布了V1.1.0版本,这次更新支持 ...

  10. 深入学习Java对象创建的过程:类的初始化与实例化

    在Java中,一个对象在可以被使用之前必须要被正确地初始化,这一点是Java规范规定的.在实例化一个对象时,JVM首先会检查相关类型是否已经加载并初始化,如果没有,则JVM立即进行加载并调用类构造器完 ...