導航:首頁 > 源碼編譯 > 貪心演算法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相關的資料

熱點內容
日語命令性 瀏覽:259
免費的程序編譯游戲 瀏覽:889
如何安裝屏蔽的APP 瀏覽:196
豬臉識別app如何下載 瀏覽:154
卓嵐串口伺服器如何使用 瀏覽:438
pdf周振甫 瀏覽:756
程序員35歲生日圖片 瀏覽:626
矩形密封圈的壓縮量 瀏覽:455
信息安全中圖像加密技術畢業論文 瀏覽:536
gear2刷android 瀏覽:79
怎麼用安卓下載櫻校 瀏覽:580
現在什麼app可以賺錢 瀏覽:155
基礎梁鋼筋圖紙未標注加密區間距 瀏覽:469
通達信指標源碼公式半透明 瀏覽:956
開發什麼手機app好 瀏覽:320
csgo如何在游戲里進入完美伺服器 瀏覽:190
編程教育老師成長心態 瀏覽:257
音頻採集單片機 瀏覽:590
加密管的優點 瀏覽:280
dock基礎命令 瀏覽:345