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也算赢. 现 ...
随机推荐
- css3系列之详解perspective
perspective 简单来说,就是设置这个属性后,那么,就可以模拟出像我们人看电脑上的显示的元素一样.比如说, perspective:800px 意思就是,我在离屏幕800px 的地方观看这 ...
- x32下PsSetLoadImageNotifyRoutine的逆向
一丶简介 纯属兴趣爱好.特来逆向玩玩. PsSetLoadImageNotifyRoutine 是内核中用来监控模块加载.操作系统给我们提供的回调. 我们只需要填写对应的回调函数原型即可进行加监控. ...
- 配置多个JDK存在的问题与解决方案 (亲测可用)
安装多个JDK时的技巧 (亲测可用) 我的电脑本来是JDK8的,后来的想在不同的JDK版本下测试JDK的垃圾回收器. 一开始的的思路是,先安装JDK,为每个JDK配置自己的家目录,然后在想用哪个版本的 ...
- spark shuffle写操作三部曲之BypassMergeSortShuffleWriter
前言 再上一篇文章 spark shuffle的写操作之准备工作 中,主要介绍了 spark shuffle的准备工作,本篇文章主要介绍spark shuffle使用BypassMergeSortSh ...
- Unittest 支持 case 失败后自动截图功能的另外两种方式
原生的unittest框架是不支持case失败后自动截图的功能的,网上看了大家的解决办法,大体上分为两种:1.要么加装饰器2.也有人封装断言这里我们看看还有没有其他的更加方便的方法值得大家一起探讨一下 ...
- 【java提高】(17)---Java 位运算符
Java 位运算符 &.|.^.~.<<.>> 以前学过有关java的运算符,不过开发了这么久也很少用过这个.现在由于开发需要,所以现在再来回顾整理下有关java的运算 ...
- Spring.Net 依赖注入
一.Spring.Net概念 编程模型(Ioc,DI方式) IoC:控制反转 原来创建对象的权利由程序来控制就是new实例,IoC就是改由容器来创建,相当于一个工厂, DI:依赖注入 没有IoC就没有 ...
- JS扫雷小游戏
HTML代码 <title> 扫雷 </title> <!-- ondragstart:防拖拽生成新页面 oncontextmenu:屏蔽右键菜单--> <b ...
- 用 Python 分析上网记录,发现了很多不可思议的事
摘要:分享个 Python 神工具. 长时间使用浏览器会积累大量浏览器历史记录,这些是很隐私的数据,里面甚至可能有一些不可描述的网站或者搜索记录不想让别人知道. 不过,我们自己可能会感兴趣,天天上 ...
- 《Java 8 in Action》Chapter 1:为什么要关心Java 8
自1998年 JDK 1.0(Java 1.0) 发布以来,Java 已经受到了学生.项目经理和程序员等一大批活跃用户的欢迎.这一语言极富活力,不断被用在大大小小的项目里.从 Java 1.1(199 ...