当前位置:网站首页>Codeworks round 681 (Div. 2) supplement
Codeworks round 681 (Div. 2) supplement
2022-07-05 08:52:00 【Qizi K】
B. Saving the City
The question :1 For bombs ,0 On behalf of the open space . Each time the bomb is detonated, it will be accompanied by the detonating coordinates +1&&-1 Bombs . Give a bomb (b) And light the bomb (a) The money needed , Ask for the minimum money to detonate all bombs .
tips: Must light a bomb . If the placement fee >= Ignition cost , Then it must not be placed ; conversely , Traverse from the beginning , Every time a new bomb is found , Compare (pos - lastpos - 1) * b And a, The former is a small bomb , On the contrary, ignite a new bomb .
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int t,n,a,b,len;
char boom[N];
int main(){
cin >> t;
while(t--){
scanf("%d%d%s",&a,&b, boom + 1);
len = strlen(boom + 1);
int ans = 0, idx = 1;
if(a <= b){
while(idx <= len){
while(boom[idx] == '0' && idx <= len) idx ++;
if(idx <= len) ans += a;
while(boom[idx] == '1' && idx <= len) idx ++;
}
}else{
int lastpos = 0;
while(boom[idx] == '0' && idx <= len) idx ++;
if(idx <= len) ans += a, lastpos = idx, idx++;
while(idx <= len){
//printf("idx = %d last = %d ans = %d\n", idx,lastpos,ans);
while(boom[idx] == '1' && idx <= len) idx ++, lastpos ++;
while(boom[idx] == '0' && idx <= len) idx ++;
if(idx > len) break;
if((idx - lastpos - 1) * b <= a) ans += (idx - lastpos - 1) * b;
else ans += a;
lastpos = idx, idx++;
}
}
printf("%d\n", ans);
}
return 0;
}
C. The Delivery Dilemma
The question : The main points of n dish . You can pick up each dish by yourself , You can also take out . If you go by yourself, you must pick it up one by one , Takeout can be delivered directly to home . Ask for the shortest time to get n Time to order .
tips: Two points answer . Note that the minimum time is not necessarily taken in the takeout time .
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 200010;
int t,n;
struct node{
int a, b;
}book[N];
int cmp(node n1, node n2){
return n1.a < n2.a;}
bool check(ll x){
ll sum = 0;
for(int i = 1; i <= n; ++i){
if(book[i].a <= x) continue;
else sum += book[i].b;
}
return sum <= x;
}
int main(){
cin >> t;
while(t--){
cin >> n;
ll minn = 0;
for(int i = 1; i <= n; ++i) scanf("%d",&book[i].a);
for(int i = 1; i <= n; ++i) scanf("%d",&book[i].b), minn += (ll)book[i].b;
sort(book + 1, book + 1 + n, cmp);
if(minn <= book[1].a){
printf("%lld\n", minn);
continue;
}
ll ans = 0, l = book[1].a, r = book[n].a;
while(l <= r){
ll mid = l + r >> 1;
if(check(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
printf("%lld\n", ans);
}
return 0;
}
D. Extreme Subtraction
The question : Give a column number , There are two operations :
A. front k Numbers each -1
B. after k Numbers each -1
k Take at will . Can they all become 0.
tips: greedy . The smaller the current number is, the better .
#include<bits/stdc++.h>
using namespace std;
const int N = 30010;
int t, n, a;
int main(){
cin >> t;
while(t--){
scanf("%d",&n);
int idx = 1, last = 1e9, tmp = 0;
bool flag = true;
for(; idx <= n; ++idx){
scanf("%d", &a);
if(last >= a) last = a;
else{
tmp = last;
last = a - last;
break;
}
}
for(idx ++; idx <= n; ++idx){
scanf("%d", &a);
if(a < last) flag = false;
else{
tmp = min(a - last, tmp);
last = a - tmp;
//printf("tmp = %d last = %d\n", tmp,last);
}
}
(flag) ? puts("YES") :puts("NO");
}
return 0;
}
边栏推荐
- C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
- C语言标准函数scanf不安全的原因
- [formation quotidienne - Tencent Selection 50] 557. Inverser le mot III dans la chaîne
- Reasons for the insecurity of C language standard function scanf
- Mengxin summary of LCs (longest identical subsequence) topics
- How many checks does kubedm series-01-preflight have
- kubeadm系列-00-overview
- Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
- OpenFeign
- Redis实现高性能的全文搜索引擎---RediSearch
猜你喜欢

Pytorch entry record

How to manage the performance of R & D team?

Mathematical modeling: factor analysis

TF coordinate transformation of common components of ros-9 ROS

Guess riddles (6)

AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
![C [essential skills] use of configurationmanager class (use of file app.config)](/img/8b/e56f87c2d0fbbb1251ec01b99204a1.png)
C [essential skills] use of configurationmanager class (use of file app.config)

C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)

An enterprise information integration system

319. Bulb switch
随机推荐
asp.net(c#)的货币格式化
轮子1:QCustomPlot初始化模板
【日常訓練--騰訊精選50】557. 反轉字符串中的單詞 III
Solution to the problem of the 10th Programming Competition (synchronized competition) of Harbin University of technology "Colin Minglun Cup"
AdaBoost use
My experience from technology to product manager
Meta tag details
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
Codeworks round 638 (Div. 2) cute new problem solution
Multiple linear regression (sklearn method)
RT thread kernel quick start, kernel implementation and application development learning with notes
EA introduction notes
520 diamond Championship 7-4 7-7 solution
[牛客网刷题 Day4] JZ32 从上往下打印二叉树
猜谜语啦(8)
Multiple linear regression (gradient descent method)
Guess riddles (142)
某公司文件服务器迁移方案
Ros-11 common visualization tools
Guess riddles (6)