CodeForces Round #514 (div2)
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 ;
}
题意:一次能给边上一圈填上'#',问这个图形合法不合法。填的时候不能越界。
直接去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 ;
}
题意:给你[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 ;
}
题意:有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 ;
}
题意:给定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)的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
- Codeforces Round #360 div2
Problem_A(CodeForces 688A): 题意: 有d天, n个人.如果这n个人同时出现, 那么你就赢不了他们所有的人, 除此之外, 你可以赢他们所有到场的人. 到场人数为0也算赢. 现 ...
随机推荐
- &= 的含义
这是一个缩略式子,展开之后的结果是a = a & b;&是按位与的操作符. 按位与运算:参加运算的两个数据,按二进位进行“与”运算.如果两个相应的二进位都为1,则该位的结果值为1,否则 ...
- 阿里云Linxu下的Mysql安装与配置
说明:本文主要详细介绍了关于如何在阿里云ECS服务器上安装并配置Mysql 环境:Centos 7版本,阿里云部署好系统后会默认安装mariadb数据库 1.删除阿里云自带的MariaDB # rpm ...
- 恐怖的Hibernate和JavaFX Table CallBack!
目录 [隐藏] 1 Hibernate 2 JavaFX Table Hibernate 最近在做 JavaFX 应用,不管再怎么避免数据持久化,但面对几十万的数据量的时候也只能乖乖的去配置持久层框架 ...
- 七天学会NodeJS——第一天
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:http://nqdeng.github.io/7-days-nodejs Node.js 是一个能 ...
- 从boosting谈起
Boosting 将一些表现效果一般(可能仅仅优于随机猜测)的模型通过特定方法进行组合来获得一个表现效果较好的模型.抽象地说,模型的训练过程是对一任意可导目标函数的优化过程. Adaptive boo ...
- 从头开始制作OJ-在线IDE的搭建
大家好,我是Fred913. 之前,我看过各种OJ(OpenJudge) 但是,还是没有自己做的好. 所以,我就来写了这篇教程. 环境 这次,我打算使用这些:PHP 5.6 Nginx/Apache ...
- 自定义GroupBox
public partial class mGroupBox : GroupBox { private Color _TitleBackColor = Color.Black; private Fon ...
- 监控JVM
WAS配置visualVM 在was控制台:找到应用程序服务器--java和进程管理--进程定义--JAVA虚拟机/通用JVM 参数 ,对应英文Application servers > ser ...
- R语言中如何找出在两个数据框中完全相同的行(How to find common rows between two dataframe in R?)
I would like to make a new data frame which only includes common rows of two separate data.frame. ex ...
- 小白学Python(2)——常用Python编程工具,Python IDE
下载好Python,但是如何开始编程呢? 有几种方法, 1.第一个就是command lind 即为命令行的方式,也就是我们常说的cmd. 输入 win+ cmd 在命令行中再输入 python,即可 ...