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

临沂网站建设 百度优化东莞浩智网站建设多少钱

临沂网站建设 百度优化,东莞浩智网站建设多少钱,门户网站解决方案,网站留言短信通知 源码题意#xff1a; 给n个小朋友分发糖果#xff0c;但小朋友们之间有嫉妒心。接下来m行#xff0c;每行三个数#xff0c;分别表示小朋友A希望B得到的糖果不能比他多x个。要求你计算在满足所有小朋友的条件的情况下最多需要准备多少颗糖。 题目#xff1a; During the ki…题意 给n个小朋友分发糖果但小朋友们之间有嫉妒心。接下来m行每行三个数分别表示小朋友A希望B得到的糖果不能比他多x个。要求你计算在满足所有小朋友的条件的情况下最多需要准备多少颗糖。 题目 During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had flymouse distribute them. All the kids loved candies very much and often compared the numbers of candies they got with others. A kid A could had the idea that though it might be the case that another kid B was better than him in some aspect and therefore had a reason for deserving more candies than he did, he should never get a certain number of candies fewer than B did no matter how many candies he actually got, otherwise he would feel dissatisfied and go to the head-teacher to complain about flymouse’s biased distribution. snoopy shared class with flymouse at that time. flymouse always compared the number of his candies with that of snoopy’s. He wanted to make the difference between the numbers as large as possible while keeping every kid satisfied. Now he had just got another bag of candies from the head-teacher, what was the largest difference he could make out of it? Input The input contains a single test cases. The test cases starts with a line with two integers N and M not exceeding 30 000 and 150 000 respectively. N is the number of kids in the class and the kids were numbered 1 through N. snoopy and flymouse were always numbered 1 and N. Then follow M lines each holding three integers A, B and c in order, meaning that kid A believed that kid B should never get over c candies more than he did. Output Output one line with only the largest difference desired. The difference is guaranteed to be finite. Sample Input 2 2 1 2 5 2 1 4 Sample Output 5 Hint 32-bit signed integer type is capable of doing all arithmetic. 分析 1.这道题目是典型的差分约束系统小于等于是最短路 大于等于是最长路核心在于xj-xibk会发现它类似最短路中的三角不等式d[v]d[u]w[u,v]即d[v]-d[u]w[u,v]即从u指向v建边num[B]num[A]x。求最大值的话就是跑1-n的最短路对应求最小值就是跑1-n的最长路。此题用队列的话会T掉可以改成栈或者想办法优化。 2.关于差分约束选择队列还是堆栈当存在回路SPFA的队列实现会超时堆栈实现可以堆栈实现SPFA有时候堆栈确实比较快 都大三的老阿姨了差分约束还不熟练加油吧查缺补漏中。。。。 AC代码 #includestdio.h #includestring.h #includealgorithm using namespace std; const int inf0x3f3f3f3f; const int M3e410; const int N15e410; int n,m,k,a,b,c; int vis[M]/**在队列标志*/; int head[M]/**每个结点的头指针(或者编号)*/; int q[M]/**堆栈*/,dis[M]; struct node {int b;int c;int next; }edge[N];void add(int a,int b,int c)//加边 {edge[k].bb;edge[k].cc;edge[k].nexthead[a];head[a]k; } void SPFA(int start,int n) {int top0;for(int i1;in;i)//初始化{if(istart){q[top]i;//入栈vis[i]true;dis[i]0;}else{vis[i]false;dis[i]inf;}}while(top!0){int aq[--top];vis[a]false;for(int ihead[a];i!-1;iedge[i].next){int bedge[i].b;if(dis[b]dis[a]edge[i].c){dis[b]dis[a]edge[i].c;if(!vis[b]){vis[b]true;q[top]b;}}}} } int main() {while(~scanf(%d%d,n,m)){k0;//加边计数这个不要忘memset(head,-1,sizeof(head));for(int i0;im;i){scanf(%d%d%d,a,b,c);add(a,b,c);}SPFA(1,n);//printf(*****\n);printf(%d\n,dis[n]);//此处求n比1最多多多少糖果}return 0; } /**给n个人派糖果给出m组数据每组数据包含A、B、c 三个数 意思是A的糖果数比B少的个数不多于c,即B的糖果数 - A的糖果数 c 。 最后求n 比 1 最多多多少糖果。*/
http://www.pierceye.com/news/987907/

相关文章:

  • 手表网站建站千秋网络是家西安做网站的公司
  • 济南企业网站百度seo优化是做什么的
  • 网站颜色搭配案例wordpress洛米主题
  • 网站几个关键词网站备案为什么要关闭
  • 深圳网站制作哪家便宜怎么利用百度云盘做网站
  • 美容培训东莞网站建设做的网站上更改内容改怎么回事
  • 绵阳新农网的网站是哪个公司做的wordpress 在线教育主题
  • 大连优化网站怎样制作企业的网站
  • 网站建设邀请函北京网站优化 卓立海创
  • 公司后台的网站代理维护更新商贸有限公司注销流程
  • 网站建设工作动态wordpress次元主题
  • 手机网站源码asp网站快速排名技巧
  • 站点怎么建网页宁波网站建设设计制作公司
  • 黑龙江企业网站建设网站模板带后台 下载
  • 徐州在线制作网站营销网络是什么意思
  • 上海网站建设seo公司微信小程序制作教学
  • 信息化工作总结 网站建设十堰市有几家网站公司
  • 宠物网站建站目标做外贸的网站哪些是最好的
  • 垂直型电商网站如何做html5 开发的网站
  • 做网站可以不做后端吗渭南网站建设网站排名优化
  • 在线建站网页制作网站建设平台工商营业执照官网
  • 做网站用到的软件h5交互设计
  • 化工废料网站建设企业网站建设联系电话
  • 浙江高端网站建设公司什么是网页开发
  • 石碣网站仿做模具做外贸网站
  • 定制网站建设成本制作公司宣传片
  • 青岛低价网站建设达内it教育官网
  • 洛阳设计网站公司个人网站管理系统
  • 怎么可以预览自己做的网站天津市城乡建设网站
  • 本地网站开发宁夏建设工程招标投标信息网站