当前位置: 首页 > wzjs >正文

微网站第三方平台住房和城乡建设部门户网站

微网站第三方平台,住房和城乡建设部门户网站,会员充值消费管理系统,深圳做三网合一网站煮啵觉得贪心是一种思维,不是一种模板(虽然有部分题感觉很模板)。煮啵觉得先确定序列,然后根据序列加工,输出即可。(煮波是蒟蒻,说错莫怪) 煮啵写的是洛谷题单【算法1-5】贪心 - 题…

煮啵觉得贪心是一种思维,不是一种模板(虽然有部分题感觉很模板)。煮啵觉得先确定序列,然后根据序列加工,输出即可。(煮波是蒟蒻,说错莫怪)

煮啵写的是洛谷题单【算法1-5】贪心 - 题单 - 洛谷,有兴趣可以看看(煮啵是两天写完的,为煮啵骄傲吧,玻璃心求夸哈)     自己点击看题哈,煮啵不喜欢刷字数

P2240 【深基12.例1】部分背包问题

P2240 【深基12.例1】部分背包问题 - 洛谷https://www.luogu.com.cn/problem/P2240煮啵觉得这是一道非常经典,一看就知道该用贪心的题

思路就是根据性价比重新排序,再计算sum

#include <iostream>
#include <algorithm>
#include<stdio.h>
using namespace std;
struct Item
{int w;//重量int v;//价值
};
Item item[101];//注意题目最多有100堆金币昂
bool cmp(Item a,Item b)
{return (a.v*b.w>b.v*a.w);//这里是(a.v/a.w>b.v/b.w)  除法转化转化成乘法,更精确
}
int main() {int n,s;//煮啵这里习惯把s定义为总质量,n设置为个数cin>>n>>s;for(int i=0;i<n;i++){cin>>item[i].w>>item[i].v;}sort(item,item+n,cmp);//性价比排序double sum=0;for(int i=0;i<n;i++){if(s>=item[i].w)//s够{s-=item[i].w;sum+=item[i].v;}else//s不够{sum+=(1.0*item[i].v/item[i].w)*s;s=0;break;}}printf("%.2lf\n",sum);//听说printf比cout效率高捏return 0;
}

P1223 排队接水

P1223 排队接水 - 洛谷https://www.luogu.com.cn/problem/P1223煮啵觉得这道题跟前一道思路差不多,先排序,再计算

#include <iostream>
#include <algorithm>
#include<stdio.h>
using namespace std;
struct Item
{int t;//时间int p;//人
};
Item item[1001];//注意题目最多有1000人昂
bool cmp(Item a,Item b)
{return a.t<b.t;
}
int main() {int n;cin>>n;for(int i=0;i<n;i++){cin>>item[i].t;item[i].p=i+1;}sort(item,item+n,cmp);//用时从短到长排序long long sum=0;
//为什么用long long 呢,因为最多有1000人,
//最长时间为10^6,这样一算sum肯定超过10^9.3,所以噜for(int i=0;i<n;i++)//不用等最后一个人{sum+=item[i].t*(n-i-1);printf("%d ",item[i].p);}printf("\n");printf("%.2lf\n",(double)sum/n);//听说printf比cout效率高捏return 0;
}

煮啵因为不注意数据溢出,MC很多次了,可恶!!!!!

P1803 凌乱的yyy / 线段覆盖

https://www.luogu.com.cn/problem/P1803https://www.luogu.com.cn/problem/P1803

煮啵这题不会(惭愧),煮啵拿着s死命算,没算出来(小丑)。煮啵去看题解了,大佬果然是大佬,本蒟蒻拍手叫绝!!!

show time:这个题,先画时间数轴,发现了啥?这不是只要根据e排好序比较前一个时间段的e和后一个时间段的s不得了,而且第一个时间段的s不影响最终结果的呀!(完结撒花)

#include <iostream>
#include <algorithm>
#include<stdio.h>
using namespace std;
struct Item
{int s;//开始时间int e;//结束时间
};
Item item[1000001];//注意题目最多有10^6昂
bool cmp(Item a,Item b)
{return a.e<b.e;
}
int main() {int n;cin>>n;for(int i=0;i<n;i++){cin>>item[i].s>>item[i].e;}sort(item,item+n,cmp);//按e从早到晚int t=1;//第一段时间哈int t_end=item[0].e;//记忆一下e的值,要跟下一个时间段的s对比的勒for(int i=1;i<n;i++){if(item[i].s>=t_end){t++;t_end=item[i].e;//更新}}cout<<t<<endl;return 0;
}

煮啵这里犯了一个致死的错误:

    for(int i=1;i<n;i++){
注意这里//int t_end=item[0].e;//记忆一下e的值,要跟下一个时间段的s对比的勒if(item[i].s>=t_end){t++;t_end=item[i].e;//更新}}

煮啵把"int t_end=item[0].e;"循环初始化了(别骂了别骂了)

P1090 [NOIP 2004 提高组] 合并果子

P1090 [NOIP 2004 提高组] 合并果子 - 洛谷https://www.luogu.com.cn/problem/P1090这道题煮啵很喜欢,因为用到了新东西嘿嘿嘿(煮啵不是变态奥)

#include <iostream>
#include <queue>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
priority_queue<int,vector<int>,greater<int> > pq;//优先队列的小顶堆
int main() {int n;cin>>n;for(int i=0;i<n;i++){int x;cin>>x;pq.push(x);//插入/优先队列}long long sum=0;while(pq.size() > 1){int a=pq.top();pq.pop();//读取顶堆元素后移除队列int b=pq.top();pq.pop();pq.push(a+b);//插入,解决要重排的问题(好爱好爱)sum+=(a+b);}cout<<sum<<endl;//输出,deepseek说printf和cout在小范围没差qaq}

煮啵觉得超重要:

push(x) 的作用

  • 将 x 插入优先队列,并自动调整堆结构,保证堆的性质(最小的元素在堆顶)。

pq.pop() 的功能

  • 移除堆顶元素

    • 在优先队列中,pop() 会 删除队列顶部的元素(即优先级最高的元素)。

    • 如果优先队列是 小顶堆priority_queue<int, vector<int>, greater<int>>),则 pop() 会移除 最小的元素

    • 如果优先队列是 大顶堆(默认 priority_queue<int>),则 pop() 会移除 最大的元素

  • 调整堆结构

    • 删除堆顶元素后,优先队列会自动调整内部结构,使得新的堆顶元素仍然符合堆的性质(最小堆或最大堆)。

pq.top():访问堆顶元素(不删除)

  • 返回优先队列的 堆顶元素(即当前优先级最高的元素)。

  • 不删除元素,只读取它的值。

pq.empty():检查队列是否为空

  • 返回 true 如果队列为空,否则返回 false

  • 常用于循环终止条件 或 防止 top()/pop() 空队列访问

pq.size():返回队列中的元素个数

  • 返回当前优先队列中的 元素数量

  • 可用于判断是否还需要继续处理。

P3817 小A的糖果

P3817 小A的糖果 - 洛谷https://www.luogu.com.cn/problem/P3817煮啵这题,这题思路不够严谨,不够贪心。煮啵觉得自己很容易第一反应是这段代码,所以还是放出来吧。

#include <iostream>
#include <queue>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {int n,x;cin>>n>>x;int arr[n];for(int i=0;i<n;i++){cin>>arr[i];}long long sum=0;for(int i=0;i<n-1;i++){int a=0;//左边超值int b=0;//右边超值if(arr[i]>x){a=arr[i]-x;}if(arr[i]+arr[i+1]>x){b=arr[i+1]+arr[i]-x;arr[i+1]=arr[i+1]-b;}sum+=(a+b);}if(arr[n-2]+arr[n-1]>x){sum+=arr[n-2]+arr[n-1]-x;}cout<<sum<<endl;}

煮啵 想的是,有事没事直接删右边,但是可能删左边是最优QAQ

煮啵调试了一波,自信又回来了

#include <iostream>
#include <queue>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {int n,x;cin>>n>>x;int arr[n];for(int i=0;i<n;i++){cin>>arr[i];}long long sum=0;for(int i=0;i<n-1;i++){int a=0;//左边超值int b=0;//右边超值if(arr[i]>x){a=arr[i]-x;
///注意这里/左边值要改变罢了arr[i]=x;}if(arr[i]+arr[i+1]>x){b=arr[i+1]+arr[i]-x;arr[i+1]=arr[i+1]-b;}sum+=(a+b);}if(arr[n-2]+arr[n-1]>x){sum+=arr[n-2]+arr[n-1]-x;}cout<<sum<<endl;}


文章转载自:

http://bkgA81j1.zfyfy.cn
http://aXqZFS5s.zfyfy.cn
http://wsfQ4ywm.zfyfy.cn
http://R0xU9vhI.zfyfy.cn
http://AoII28Dm.zfyfy.cn
http://7QJa2oOA.zfyfy.cn
http://tn3Lae3S.zfyfy.cn
http://4Jai9JbW.zfyfy.cn
http://PUCqHrsc.zfyfy.cn
http://i7LV8P9j.zfyfy.cn
http://EjpIsHgN.zfyfy.cn
http://jh7auvMA.zfyfy.cn
http://5wnUnZrb.zfyfy.cn
http://DqtAafGS.zfyfy.cn
http://COLuHIcK.zfyfy.cn
http://aEhNq4ha.zfyfy.cn
http://o39ypSU4.zfyfy.cn
http://rSyhYFUI.zfyfy.cn
http://rfH7LJzH.zfyfy.cn
http://2vQUpRFj.zfyfy.cn
http://BzM9LeAi.zfyfy.cn
http://zr4ZONqZ.zfyfy.cn
http://2OG3c6LX.zfyfy.cn
http://bFFhnVgx.zfyfy.cn
http://wk31Gfk2.zfyfy.cn
http://EB360Vjh.zfyfy.cn
http://KTM4amQ5.zfyfy.cn
http://1ciFwlra.zfyfy.cn
http://PhWDfAqc.zfyfy.cn
http://1Ty6ALTj.zfyfy.cn
http://www.dtcms.com/wzjs/648602.html

相关文章:

  • wordpress+vps建站汕头网站建设维护
  • 做网站网页的工作怎么样用js做简单的网站页面
  • 西安微网站开发北京示范校建设网站
  • 开封网站制作专业精准网络营销推广
  • 专业型企业网站有哪些短视频营销
  • 制作网站模板教程甘肃省建设局网站首页
  • 钓鱼网站代做做整站优化
  • 滨州网站开发公司电脑网
  • 纯flash网站欣赏影楼手机网站设计
  • 小米的网站设计惠州seo顾问
  • 攻击网站步骤俄文网站制作
  • 高仿id97网站模板温州seo招聘
  • 网站建设产品分割室内设计自学网站
  • 有没有专门做帽子的网站flash网站带后台
  • 为什么做不了自己的网站网站开发最严重的问题
  • 网站建设的流程简答题招远网站建设价格
  • 网站服务器租赁哪家好江苏元鼎建设工程有限公司网站
  • 网站建设邮如何使用家里电脑做网站服务器
  • 做网站要学什么杭州有名的纯设计公司
  • 深圳设计网站公司哪家好wordpress slug translate
  • 宁波网站推广找哪家公司怎么才能百度做网站
  • asp网站数据库连接软件开发学什么专业好
  • 网站备案流程阿里云微信公众号微信公众平台
  • win2008sr怎么用iis做网站大宗交易平台有哪些
  • 网站开发和桌面开发哪个难网站主题模板制作
  • 专做热血电影的网站wordpress多域名不稳定
  • 做一个flash网站多少钱wordpress询盘功能
  • 海珠网站建设哪家好东莞常平镇地图全图
  • 网站开发建设技术规范书全屏网站设计技巧
  • 烟台个人网站建设凡客网登录