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也算赢. 现 ...
随机推荐
- Java动态,安全追踪工具
Java动态,安全追踪工具 在我们日常的开发中,总是难以避免的要解决线上的问题.如果线上的问题我们在本地调试的时候无论调试多少次发现明明本地调用了这个方法呀,怎么线上就是没调呢?还有就是出了问题的时候 ...
- 0R电阻在PCB布线中对布线畅通的一个小妙用
在PCB布线中,我们都会尽量节约板子空间,将元器件排布的紧密一些,难免会遇到布线不通的时候. 博主下面就来说一个关于0R电阻在PCB布线使之畅通的一个小妙用. 使用0R电阻前 假设我们这个TXD的线周 ...
- JAVA jobs
Java岗位1, SpringMVC, spring, mybaits2, 高并发编程3, mysql或者oracle SQL调优及函数,存储过程,JOB调度
- python basemap readshapefile二三事
今天要用到basemap读取shp文件报错,查了很多资料,都没有解决. 先是: fig,ax = plt.subplots(figsize=(15,10)) from mpl_toolkits.bas ...
- Vue系列:Websocket 使用配置
WebSocket 是什么? WebSocket 是一种网络通信协议.而且是在 HTML5 才开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. 为什么需要 WebSocket ? 了解计算 ...
- 最简单的DWR例子
什么是DWR? DWR是一个Open Source的 java项目.DWR可以让JavaScript调用运行在Web服务器里面的JAVA程序.简单一点或者专业一点就是Easy AJAX for JAV ...
- Linux 精确判断是否同一文件--及终端获取字符串md5 的值
背景 今天发现一个同事用 文件大小 对比,来判断编译所得的一个可执行文件是不是同一个文件. 讲道理 这种方式出错的概率很低,但是用这样的方法,一旦出错就容易被坑一把狠的. 所以我来分享一下 md5 在 ...
- GOF23-工厂模式
1.什么是工厂模式 就是实现创建者与调用者分离,工厂模式的核心(灵魂)其实就是:分工. 2.工厂模式有哪些 简单工场模式(静态工厂) 简单工厂模式也叫静态工厂模式,就是工厂类一般使用静态方法,通过 ...
- PostgreSQL创建扩展出错
问题: loraserver_as=# create extension pg_trgm; ERROR: could not open extension control file "/us ...
- spring-cloud-config 配置中心快速上手
spring-cloud-config 配置中心实现 Spring Cloud Config 用于为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,分为server端和client端. s ...