21山东省赛DGH

news/2025/1/19 15:34:04/

目录

D

Dyson Box模拟

G

Grade Point Average除法模拟

H

Adventurer's Guild简单dp


D

Dyson Box模拟

In the only example, the inside of the box is as below, and the bold lines mark the outline of all the cubes.

After the 111-st event:


After the 222-nd event:



After the 333-rd event:



After the 444-th event:

 题意:每次在矩阵内某处产生一个箱子,每个箱子会受到水平力或竖直力作用,输出每种力情况下当前箱子露出的边数.

思路:模拟一下,竖直和水平的情况分开讨论.每次产生一个箱子,先让当前的总边长加4.然后模拟各种会使露出边长减小的情况,比如叠在某个箱子上,或者紧贴着某些箱子.

#include <iostream>
#include<ctime>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
struct node {int x, y;
}per[N];
int m1[N] = { 0 }, m2[N] = { 0 };
int main()
{ios::sync_with_stdio(false); cout.tie(NULL);int n;cin >> n;int sum1 = 0, sum2 = 0;for (int j = 1; j <= n; j++) {sum1 += 4; sum2+= 4;int t1, t2;cin >> per[j].x >> per[j].y;t1 = per[j].x; t2 = per[j].y;if (m1[t1])sum1 -= 2;if (m1[t1] + 1 <= m1[t1 - 1] )sum1 -= 2;if (m1[t1] + 1 <= m1[t1 + 1])sum1 -= 2;if (m2[t2])sum2 -= 2;if (m2[t2] + 1 <= m2[t2 + 1])sum2 -= 2;if (((m2[t2] + 1) <= m2[t2 - 1]))sum2 -= 2;m1[per[j].x]++; m2[per[j].y]++;//记录箱子摆放情况cout << sum1 << " " << sum2 << endl;}
}

G

Grade Point Average除法模拟

题意:对一段数列求取平均数,小数点后保留k位,不四舍五入.

思路:除法模拟.

#include<iostream>
#include<vector>
#include<string>
using namespace std;
void div(long long s,int n,int k){vector<int>c;string ans=to_string(s/n)+".";//先取出整数部分s%=n;while(k--){//开始模拟小数点后的除法int t=(s*10)/n;//除完得到的数ans+=to_string(t);s=(s*10)%n;//除完剩下的数}cout<<ans<<endl;
}
int main(){
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);int n,k;cin>>n>>k;long long  sum=0;for(int j=1;j<=n;j++){int t;cin>>t;sum+=t;}div(sum,n,k);
}

H

Adventurer's Guild简单dp

 

题意:其实就是冒险者有生命值和耐力值两种限制,打完每个怪物会扣除对应的生命值和耐力值.但会得到对应的价值. 生命值<=0则死亡,耐力值小于0的部分会由生命值承担. 目前有n个怪物,求你能得到的最大价值.

思路:其实是一道很明显的01背包问题,但是多了个耐力值的限制,不过也很好讨论耐力值小于0的情况转移到耐力值为0生命值而外减去对应的溢出耐力值即可.

状态转移方程:

 dp[j][i][k] = dp[j - 1][i][k]; 
if (k < per[j].s) {if (i - per[j].h - (per[j].s - k) > 0) dp[j][i][k] = max(dp[j - 1][i][k], dp[j - 1][i - per[j].h - (per[j].s - k)][0] + per[j].w);else dp[j][i][k] = max(dp[j - 1][i][k], dp[j - 1][i - per[j].h][k - per[j].s] +per[j].w);

 数据1000*300*300看起来好像能撑的过去

如果直接三维暴力 话

#include <iostream>
#include<ctime>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#define ll long long
using namespace std;
const int N = 1e3 + 10;
ll n, hh, ss;
struct node {int h, s, w;
}per[N];
int  dp[1010][310][310] ;
int main()
{ios::sync_with_stdio(false); cout.tie(NULL);cin >> n >> hh >> ss;for (int j = 1; j <= n; j++) {ll h, s, w;cin >> h >> s >> w;per[j].h = h, per[j].s = s, per[j].w = w;}for (int j = 1; j <= n; j++) {for (int i = 1; i <= hh; i++) {for (int k = 0; k <= ss; k++) {dp[j][i][k] = dp[j - 1][i][k];//注意这里如果没有成功转移则继承上一个状态if (i > per[j].h) {if (k < per[j].s) {if (i - per[j].h - (per[j].s - k) > 0) {dp[j][i][k] = max(dp[j - 1][i][k], dp[j - 1][i - per[j].h - (per[j].s - k)][0] + per[j].w);}}else {dp[j][i][k] = max(dp[j - 1][i][k], dp[j - 1][i - per[j].h][k - per[j].s] + per[j].w);}}}}}cout << dp[n][hh][ss];
}

 

 还是爆内存了,于是乎想到01背包的二维优化.

#include <iostream>
#include<ctime>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#define ll long long
using namespace std;
const int N = 1e3 + 10;
ll n, hh, ss;
struct node {ll h, s, w;
}per[N];
ll dp[310][310]={0};
int main()
{ios::sync_with_stdio(false); cout.tie(NULL);cin >> n >> hh >> ss;for (int j = 1; j <= n; j++) {ll h, s, w;cin >> h >> s >> w;per[j].h = h, per[j].s = s, per[j].w=w;}for (int j = 1; j <= n; j++) {for (int i = hh; i >per[j].h; i--) {for (int k = ss; k >=0; k--) {if (k - per[j].s < 0) {if (i - per[j].h - (per[j].s - k) > 0)dp[i][k] = max(dp[i - per[j].h - (per[j].s - k)][0] + per[j].w, dp[i][k]);}else {dp[i][k] = max(dp[i - per[j].h][k - per[j].s] + per[j].w, dp[i][k]);}}}}cout << (dp[hh][ss]) << endl;
}

 


http://www.ppmy.cn/news/705751.html

相关文章

二叉树前序遍历、中序遍历、后序遍历、层序遍历的直观理解

0. 写在最前面 希望大家收藏&#xff1a; 本文持续更新地址&#xff1a;https://haoqchen.site/2018/05/23/go-through-binary-tree/ 复习到二叉树&#xff0c;看到网上诸多博客文章各种绕&#xff0c;记得头晕。个人觉得数学、算法这些东西都是可以更直观简洁地表示&#xf…

DG概念详解

RAC&#xff0c; Data Gurad&#xff0c; Stream 是Oracle 高可用性体系中的三种工具&#xff0c;每个工具即可以独立应用&#xff0c;也可以相互配合。 他们各自的侧重点不同&#xff0c;适用场景也不同。 RAC 它的强项在于解决单点故障和负载均衡&#xff0c;因此RAC 方案常用…

BDH,CDH,DDH,DLP是什么?

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 一、BDH&#xff0c;CDH&#xff0c;DDH&#xff0c;DLP是什么&#xff1f; 1.BDH2.CDH3.DDH4.DLP总结 一、BDH&#xff0c;CDH&#xff0c;DDH&#xff0c;DLP是什…

Nginx+Tomcat(多实例)实现动静分离和负载均衡(四层、七层)

目录 一、Tomcat 多实例部署 二、反向代理的两种类型 三、NginxTomcat实现负载均衡和动静分离&#xff08;七层代理&#xff09; 1.动静分离和负载均衡原理 2.实现方法 3.部署实例 &#xff08;1&#xff09;部署Nginx负载均衡服务器 &#xff08;2&#xff09;配置Tom…

dng是什么格式?dng格式用什么软件打开?dng格式怎么转换成jpg

前言 第一次遇见dng格式的朋友们&#xff0c;一定会有下列疑惑&#xff1a; dng是什么格式&#xff1f;dng格式怎么打开&#xff1f;dng文件怎么转换jpg&#xff1f;dng文件怎么转换png&#xff1f;dng文件怎么转换gif&#xff1f; 今天我们就来一个个的解释下你的疑惑。 d…

CDH是什么?

CDH CDH是Cloudera的100&#xff05;开放源代码平台发行版&#xff0c;包括Apache Hadoop&#xff0c;是专门为满足企业需求而构建的。CDH可立即提供企业使用所需的一切。通过将Hadoop与十几个其他关键的开源项目集成在一起&#xff0c;Cloudera创建了功能先进的系统&#xff0…