导航:首页 > 源码编译 > 贪心算法hdu

贪心算法hdu

发布时间:2022-07-27 06:45:11

㈠ 一个简单的ACM问题,杭电的1050

建议你把题目或题目大意贴出来

㈡ 跪求关于贪心算法,HDU 1050测试数据全对,实在找不出错,

// 我的AC代码
// 我可不知道我的写法是不是贪心,反正已经A了
// 怎么写的时候没啥贪心的感觉呢
#include <stdio.h>
#define N 1000
int main()
{
int n;
int t;
int i,j;
int max;
int a[N];
while (scanf("%d",&n)!=EOF)
{
while (n--)
{

for (i=0;i<N;i++) a[i]=0;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&i,&j);
if (i>j)
{
max=i;i=j;j=max;
}
if (i%2==0) i=i-1;
if (j%2!=0) j=j+1;
for (i;i<=j;i++) a[i]++;
}
max=0;
for (i=0;i<N;i++)
{
if (a[i]>=max)
{
max=a[i];
}
}
printf("%d\n",max*10);
}
}
return 0;
}

㈢ 2570 大牛们请教,总是WA,思路跟HDU论坛上一样啊

你代码的主要问题是实数的处理不到位,给你一组错误的数据,题目能用整数做就不要用实数做,实数在计算机当中的表示是近似值而不是准确值
1
2 1 6
5 7
(0.05+0.07不一定等于0.06+0.06哦)
对于实数的处理,一般给出一个误差eps,认为两个数只要在这个误差内,就算两个数相等

下面给出我的代码。
//Code by SCROOKE 2010-1-28 11:21:07
//Code for 紫英落 ()
//HDU 2570

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
int n,p,q,r,s,t;
int a[100];
scanf("%d",&n);
while (n--)
{
scanf("%d%d%d",&p,&q,&t);
for (s=0;s<p;s++)
{
scanf("%d",&a[s]);
a[s]-=t;
}
sort(a,a+p);
r=0;
for (s=0;s<p;s++)
if (r+a[s]<=0)
r+=a[s];
else break;
if (s)
printf("%d %.2f\n",s*q,0.01*t+r*0.01/s);
else printf("%d %.2f\n",0,0);
}
return 0;
}

㈣ HDU1874 用基于优先队列的Dijkstra写

你用queue写看有没问题嘛,WA可能是你有些特殊情况没考虑呢,用priority_queue和queue用法和思想差不多。
反正Dijkstra算法就是一种贪心算法嘛,用priority_queue把距离短的路径排在前面。

㈤ 杭电ACM2037(今年暑假不AC)。 谁能帮我解释下这个代码,从别人那拷过来的。看不懂,再次谢谢大家了。

这是贪心算法。。。
不妨用Begin[i]和End[i]表示事件i的开始时刻和结束时刻。则原题的要求就是找一个最长的序列a1<a2<…<an,满足:
Begin[a1]<End[a1]<=…<= Begin[an]<End[an]
可以证明,如果在可能的事件a1<a2<…<an中选取在时间上不重叠的最长序列,那么一定存在一个包含a1(结束最早)的最长序列。
(证明:略)

要对结束时间从小到大 排下序。。

楼主可以去HDOJ论坛下载 贪心算法的课件。。
课件下载地址: http://acm.h.e.cn/forum/read.php?tid=3315
这是里面的一道例题。。

㈥ h moving tables程序显示wa

这个是要用贪心算法或把走廊分为200段的那个方法的,你这里应该要对t【】进行从小到大的排序,而且最后 if (flag[j]==0 && (s[i]>t[j] || t[i]<s[j]))这里并不止这样,s【i】的值应该用一个变量来存放,当找到满足条件的时候,还要更换你的那个变量的。。。。。。。。。。。

㈦ 杭电acm1052题,贪心问题,为什么WA求解答~~~谢谢哈

给你一组用例
3
100 50 10
200 100 30

你的程序结果是-200
正确的结果是0。(100-100, 50-30, 10-200)
你用贪心算法,贪心准则正确么?

㈧ c语言 ACM或者趣味题目

给你个题目链接,我做ACM的第一题,对我来说很简单的
不知道你怎么样
http://acm.pku.e.cn/JudgeOnline/problem?id=3028

Description

This is back in the Wild West where everybody is fighting everybody. In particular, there are n cowboys, each with a revolver. These are rather civilized cowboys, so they have decided to take turns firing their guns until only one is left standing. Each of them has a given probability of hitting his target, and they all know each other’s probability. Furthermore, they are geniuses and always know which person to aim at in order to maximize their winning chance, so they are indeed peculiar cowboys. If there are several equally good targets, one of those will be chosen at random. Note that a cowboy’s code of ethics forces him to do his best at killing one of his opponents, even if intentionally missing would have increased his odds (yes, this can happen!)

Input

On the first line of the input is a single positive integer t, telling the number of test cases to follow. Each case consists of one line with an integer 2 ≤ n ≤ 13 giving the number of cowboys, followed by n positive integers giving hit percentages for the cowboys in the order of their turns.

Output

For each test case, output one line with the percent probabilities for each of them surviving, in the same order as the input. The numbers should be separated by a space and be correctly rounded to two decimal places.

Sample Input

5
2 1 100
3 100 99 98
3 50 99 100
3 50 99 99
3 50 99 98
Sample Output

1.00 99.00
2.00 0.00 98.00
25.38 74.37 0.25
25.38 49.50 25.12
25.63 24.63 49.74

阅读全文

与贪心算法hdu相关的资料

热点内容
解压一半可以取消嘛 浏览:119
住宅风水pdf 浏览:238
文件夹rundir什么意思 浏览:971
戴尔电脑如何给硬盘加密 浏览:155
androidn版本特性 浏览:930
算法期中试卷 浏览:939
php连接hbase 浏览:815
服务器的威胁性应该是什么等级 浏览:827
3d打印机的算法原理 浏览:483
腾讯云通信服务器 浏览:891
minecraft最可怕服务器地址 浏览:276
程序员选专业有必要吗 浏览:32
如何重装rpc服务器 浏览:637
程序员必备的app 浏览:167
电动汽车加密币 浏览:962
xp支持多少层文件夹 浏览:650
阿里云服务器防御指标 浏览:895
cc网络编程学习 浏览:461
单片机又叫微控制器对吗 浏览:662
安卓软件商店如何评分 浏览:657