当前位置:网站首页>2022 Hangzhou Electric Cup Super League 3
2022 Hangzhou Electric Cup Super League 3
2022-07-31 08:35:00 【right_135】
Boss Rush
题目链接:[Boss Rush](Problem - 7163 (hdu.edu.cn))
题意:Characters have multiple skills,Skill needs to be cast first,Then it will cause damage,You can only use new skills after the damage is done.,Damage is dealt second by second,The damage may be different every second,However, the sequence of skills cannot be changed,You can choose to put or not put each skill,Ask at least need how many seconds to kill the monster.
题解:二分答案,According to the time to determine whether the time can kill the monster.
从前往后依次发动若干个技能,Then the time when the next skill can be activated is equal to the sum of the time required to activate the skills in between.,因此只和之前发动过哪些技能有关.
时间复杂度: O ( n n l o g a n s ) O(n^nlog^{ans}) O(nnlogans)
//二分答案
#include <iostream>
#include <cstring>
using namespace std;
typedef long long int ll;
ll hp;
int n;
long long dp[20][100005];//存储第ibefore skillslenframe damage --前缀和
int t[100005],d[100005];//存储第iThe cast time and damage dealt time of each skill
int sum[(1<<18)+1];//s二进制 中1representativei个技能, 0Represents not letting goi个技能 sum存储当前sThe time it takes for the skill to be released
ll f[(1<<18)+1];//记录sAll skills represented by binary numbers The total amount of damage that can be caused
bool check(int x){
for(int s=0;s<(1<<n);s++){
f[s]=-1; //For the initial damage-1;
}
f[0]=0;
for(int s=0;s<(1<<n);s++){
ll w=f[s];//通过f[s]获取当前sCorresponding total damage --fArrays are computed later
if(w<0)continue;//If the damage is negative ,definitely not
if(w>=hp)return 1;//If the damage is greater thanhp...
int cur=sum[s];//当前s所花费的时间
if(cur>x)continue;//If the time taken is greater than the required time 不行了
for(int i=0;i<n;i++){
if(!((s>>i)&1)){//如果s never let goi个技能
if(cur+d[i]-1<=x){//如果加上第iThe time of a skill still does not time out ,then the damage can be added to all
f[s|(1<<i)]=max(f[s|(1<<i)],w+dp[i][d[i]-1]);
}
else{//如果超时,Then the damage can only be added to the frame that does not time out.,Also make sure to update Damage increases
f[s|(1<<i)]=max(w+dp[i][x-cur],f[s|(1<<i)]);
}
}
}
}
return 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int tt;
cin>>tt;
while(tt--){
cin>>n>>hp;
int l=0,r=0;
for(int i=0;i<n;i++){
cin>>t[i]>>d[i];//输入第iCasting time and damage time of each skill
r+=t[i]+d[i]-1;//r存储前iA skill always take time Solve the upper bound of the dichotomous answer
for(int j=0;j<d[i];j++){
cin>>dp[i][j];//输入第i个技能的第jThe damage a frame can do
}
for(int j=1;j<d[i];j++){
dp[i][j]+=dp[i][j-1];//计算第i个技能前jThe sum of the damage the frame can do
}
}
memset(sum,0,sizeof(sum));
for(int s=1;s<(1<<n);s++){
sum[s]=sum[s-(s&-s)]+t[__builtin_ctz(s&-s)];//Fast calculations with bit operations sHow long does it take to complete the corresponding skills?
//smeans just one more1,Then other skills must have been let go before,So just add on the previous basis 最新的那个1the corresponding time.
}
int ans=-1;//Initially means can't kill monsters
while(l<=r){//二分答案
int mid=(l+r)/2;
if(check(mid)){//Check when the time ismidWhen can you kill the monster
ans=mid;
r=mid-1;
}else{
l=mid+1;
}
}
cout<<ans<<'\n';
}
}
Package Delivery
题目链接:[Package Delivery](Problem - 7170 (hdu.edu.cn))
题意:总共有n件货物,Every time a pickup take at mostk件,Each item can only be picked up at one time period,问,It takes at least a few times to pick up all the goods.
题解:先按照结束时间排序,Sort by start time,Pick up sooner by end time,At the same time, check whether the goods can also be picked up according to the start time(When such goods are taken away, they need to be sorted by the end time,The later the end time, the sooner it will be picked up).
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
P no[100005];
int ql[100005],qr[100005];
bool del[100005];
priority_queue<P,vector<P>,greater<P> >que;
inline col(int i,int j){
return no[i].first<no[j].first;
}
inline cor(int i,int j){
return no[i].second<no[j].second;
}
void solve(){
memset(no,0,sizeof(no));
memset(ql,0,sizeof ql);
memset(qr,0,sizeof qr);
memset(del,0,sizeof(del));
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>no[i].first>>no[i].second;
ql[i]=qr[i]=i;
}
sort(ql+1,ql+n+1,col);//按照结束时间排序
sort(qr+1,qr+n+1,cor);//按照开始时间排序
int j=1;
int ans=0;
for(int i=1;i<=n;i++){
if(del[qr[i]])continue;
ans++;
while(j<=n&&no[ql[j]].first<=no[qr[i]].second){//Anything with a start time earlier than or equal to the end time of the current shipment can be taken away
que.push(P(no[ql[j]].second,ql[j]));//Priority queue sorted by end time
j++;
}
for(int w=1;w<=k;w++){//Take away the mostk件货物
if(que.empty())break;
pair<int,int>pa;
pa=que.top();//Priority to take away goods with an early end time
que.pop();
del[pa.second]=1;
}
}
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
}
边栏推荐
猜你喜欢

【MySQL功法】第5话 · SQL单表查询

Open Source | Commodity Recognition Recommender System

【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(下) -- 搜索历史

【插值与拟合】

Read Elephant Swap in one article, why does it bring such a high premium to ePLATO?

Ubuntu22.04安装mysql

SSM integration case study (detailed)

SSM framework explanation (the most detailed article in history)

【云原生与5G】微服务加持5G核心网

SQL 入门之第一讲——MySQL 8.0.29安装教程(windows 64位)
随机推荐
如何在一台机器上(windows)安装两个MYSQL数据库
Unreal基础概念
Failure scenarios of @Transactional annotations
Regarding "computing power", this article is worth reading
Open Source | Commodity Recognition Recommender System
哆啦a梦教你页面的转发与重定向
[Cloud native and 5G] Microservices support 5G core network
SQL 入门之第一讲——MySQL 8.0.29安装教程(windows 64位)
免安装版的Mysql安装与配置——详细教程
【云原生与5G】微服务加持5G核心网
SQL statement knowledge
Ceph single node deployment
开源|商品识别推荐系统
[Yellow ah code] Introduction to MySQL - 3. I use select, the boss directly drives me to take the train home, and I still buy a station ticket
skynet中一条消息从取出到处理完整流程(源码刨析)
MySQL 5.7 安装教程(全步骤、保姆级教程)
ONES 入选 CFS 财经峰会「2022数字化创新引领奖」
[MySQL exercises] Chapter 3 Common data types in MySQL
[What is the role of auto_increment in MySQL?】
会话技术之Coookie && Session详解