當前位置:首頁 » 編程語言 » c語言編程警察抓小偷
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言編程警察抓小偷

發布時間: 2022-10-01 10:11:53

c語言 結構體問題 問題長 高分 急

我僅給你more challenging question的實現
因為沒做錯誤處理 你輸入的時候要輸入正確的數據

// tmpdsf.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include "stdafx.h"

typedef struct item{
int id;
int value;
int weight;
}Item;
int takenvalue;
int takenweight;
Item takenTMP[11];
//int num;
int value = 0;
int weight = 0;
int total = 0;
int totalend = 0;
void printItems(Item items[], int numItems)
{
int i = 0;
for(i = 0; i < numItems; i ++)
{
if(items[i].id == 0)break;
printf("%d, %d,%d\n", items[i].id, items[i].value , items[i].weight);
}

}
void search(Item items[ ],Item taken[ ], int numItems, int maxWeight,int first)
{
int i, j;
for(i = first; i<= numItems; i++)
{
if((items[i].weight + weight) <= maxWeight)
{
takenTMP[total].id = items[i].id;
takenTMP[total].value = items[i].value;
takenTMP[total].weight = items[i].weight;
weight += items[i].weight;
value += items[i].value;
total++;
if(value > takenvalue)
{
takenweight = 0;
totalend = 0;
for(j = 0; j < total; j++)
{
taken[j].id = takenTMP[j].id;
taken[j].value = takenTMP[j].value;
taken[j].weight = takenTMP[j].weight;
takenweight += taken[j].weight;
totalend ++;
}
takenvalue = value ;
first = i+1;
taken[total+1].id = 0;
taken[total+1].value = 0;
taken[total+1].weight = 0;
search(items,taken, numItems, maxWeight, first);
}
}
}
}
int maximize(Item items[ ], int numItems, int maxWeight, Item taken[ ])
{
int first = 0;
int i;
takenvalue = 0;
for(i = 0; i<= numItems; i++)
{
total = 0;
weight = 0;
value = 0;
search(items,taken, numItems, maxWeight, i);
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
Item items[10], taken[11];
int numItems = 1;
int i = 0;
int maxWeight =0;
int quit;
for(i= 0; i< 12; i ++)
{
items[i].id = 0;
items[i].value = 0;
items[i].weight = 0;
takenTMP[i].id = 0;
takenTMP[i].value = 0;
takenTMP[i].weight = 0;
}

printf("please Enter items:\n");
while(1)
{
scanf("%d,%d,%d\n",&items[numItems - 1].id, &items[numItems - 1].value, &items[numItems - 1].weight);
if(items[numItems - 1].id == 0)break;
numItems ++;
}
printf("Enter maximum weight, W:");
scanf("%d,",&maxWeight);
maximize(items, numItems, maxWeight,taken);
printItems(taken, totalend);
printf("Items taken:");
for(i=0; i < totalend; i++)
printf("<%d, %d,%d>", taken[i].id, taken[i].value , taken[i].weight);
printf("\n");
printf("Total value: %d\n", takenvalue );
printf("Total weight: %d\n", takenweight );

scanf("%d",&quit);

return 0;
}

㈡ 用C語言來解答這道題

#include <stdio.h>

main()
{printf("啥雞把玩意兒!");
return 0;
}

㈢ 以下兩種描述分別對應哪兩種對分類演算法的評價標准

一,K-Means聚類演算法原理 k-means 演算法接受參數 k ;然後將事先輸入的n個數據對象劃分為 k個聚類以便使得所獲得的聚類滿足:同一聚類中的對象相似度較高;而不同聚類中的對象相似度較小。聚類相似度是利用各聚類中對象的均值所獲得一個「中心對 象」(引力中心)來進行計算的。 K-means演算法是最為經典的基於劃分的聚類方法,是十大經典數據挖掘演算法之一。K-means演算法的基本思想是:以空間中k個點為中心進行聚類,對最靠近他們的對象歸類。通過迭代的方法,逐次更新各聚類中心的值,直至得到最好的聚類結果。 假設要把樣本集分為c個類別,演算法描述如下: (1)適當選擇c個類的初始中心; (2)在第k次迭代中,對任意一個樣本,求其到c個中心的距離,將該樣本歸到距離最短的中心所在的類; (3)利用均值等方法更新該類的中心值; (4)對於所有的c個聚類中心,如果利用(2)(3)的迭代法更新後,值保持不變,則迭代結束,否則繼續迭代。 該演算法的最大優勢在於簡潔和快速。演算法的關鍵在於初始中心的選擇和距離公式。

㈣ get 的用法

及物動詞 vt.
1.得到, 收到
I've got your telegram.
我已經收到了你的電報。
They got notice from the police.
他們從警察那裡得到通知。
Can you get a ticket for me?
你能給我搞張票嗎?
I'll get a better position for him.
我要為他謀個更好的職位。
2.具有
3.使得
Please go and get him.
請去把他叫來。
We'll get you there somehow.
我們將設法把你送到那裡。
You must get them to come over here.
你得設法讓他們來這兒。
I can't get the car to start.
我無法使車發動起來。
I'll get the car going.
我要讓這輛車發動起來。
She got her watch robbed of.
她的手錶遭搶劫了。
How did the boy get himself dirty?
這孩子怎麼搞得這么臟?
4.(去)拿來
I'm going to get my hat from the other room.
我要到另一個房間去拿我的帽子。
5.理解, 聽到, 學得
Did you get what I mean?
你明白我的意思了嗎?
6.感染上, 得(病)
I've got a bad cold.
我得了重感冒。
7.抓住, 擊中, 殺死
The police got the thief.
警察抓住了小偷。
I got the minister on the ear with a potato.
我用土豆打中了部長的耳朵。
8.受到(懲罰等)
9.獲得;得到
10.(賣某物)掙得,獲得
11.受到;遭到;被判(刑)
12.(考試)獲得,達到
13. 與(某人)電話聯系;與(某人)通電話
14.(使)達到,處於
15.開始(感覺到、認識到、成為);達到…地步(或程度)
16.使,讓(某人或物做某事);說服(某人做某事)
17.使(某事)發生;使完成(某事)
18.有機會(做…);得到(做…的)機會
19.(使)到達,離開,沿…移動,艱難地移動
20. 使煩惱;使惱火
21.受到;收到;接到;領取,領受
22.搭上(車、船等);趕上(火車等)
23.計算出,得到
24.說服,勸說,勸導,促使(某人)做某事
We'll get him to leave.
我們會說服他離開。
25.被判(刑),受到(打擊)
to get ten years for robbery
因搶劫被判處10年徒刑
及物動詞 vt. & 不及物動詞 vi.
1.到達, 來, 往
The visitors got here last night.
遊客們是昨晚到達這里的。
After travelling all summer, I was glad to get home.
旅行了整個夏天之後, 我很高興回到了家。
We won't get anywhere that way.
那樣我們不可能有任何進展。
You'll get nowhere if you follow his instruction.
要是你按他的方法去做, 將會一事無成。
They tried to talk, but not knowing each other's language they didn't get far.
他們試圖交談, 但因彼此語言不通, 還是沒談出什麼名堂。
不及物動詞 vi.
1.開始, 逐漸
You'll get to like it in time.
你終究會喜歡它的。
He got to be rich.
他富了。
When you get to know him you'll find he is quite nice.
當你漸漸認識他時, 你會發現他很不錯。
2.成為,變為,變得,變成;(開始…)起來,逐漸…起來
She is getting old.
她開始衰老了。
3.設法對付;想法做到,竟然成功地
4.獲得利益(或財富),賺到錢
He spends all his time getting and spending.
他把他所有的時間都花在賺錢和消費上了。
系動詞 link-v.
1.遭到
He got sick.
他病了。
He got killed in the war.
他在戰爭中陣亡了。
They got punished by the teacher.
他們受到了教師的懲罰。
You nearly got hit by that car!
你差點被車撞了。
2.成為, 變得
She was getting an old woman.
她在變成一個老太太。
In this way we get better results in teaching.
這樣我們的教學效果就比較好了。
It's getting chilly.
天冷起來了。
Outside it was getting light.
外邊天已經發白了。
The days are getting longer and longer.
白天越來越長。
The food's getting cold.
飯菜快涼了。
A white dress gets dirty very fast.
白色的衣服臟得快。
He is getting old.
他老了。
The old man seems to be getting younger and younger.
這位老人似乎越來越年輕了。
I am getting restless.
我開始不耐煩了。
He got angry with me because of my remark.
他由於我講的話而生我的氣。
The UN began to get more and more powerful.
聯合國開始變得越來越強大了。
Now, now, boys and girls, don't get so excited!
好了, 好了, 同學們, 別這么激動!

㈤ pascal問題~警察抓a,b,c,d四名嫌疑犯,其中有一人是小.四人中三人說的是真話,一人說的是假話。編程找出他

1、可以分別假設A、B、C、D說的是假話,
然後檢查是否存在矛盾,排除產生矛盾的假設,
剩下的就是答案。

2、這是二部圖的問題,可以建立人與書之間關系二部圖,
然後求完美匹配,如果存在完美匹配,
則該匹配就是滿足條件的方案。

祝你好運!

㈥ free pascal編程題求解答(警察局抓了A 、B、C、D四名偷竊嫌疑犯,其中有一個是小偷。審問A說:「我……)

是C
如果A說的是真話 那麼小偷是B 由此可推出D說的也是真話
如果B說的是真話 那麼C說的也是真話
如果C說的是真話 那麼B說的是假話 小偷不是D D說的就是真話
如果D說的是真話 那麼B說的是假話 就不是D C說的是假話 那麼是C偷的 所以A說的也是假話

㈦ 如何使用面相對象編程和c++實現:警察抓小偷的任務

class Role
{
public:
Role()
{
x = Random();
y = Random();
}
inline void Up()
{
y+=5;
if(y>MAX_HEIGHT) y=MAX_HEIGHT;
}
inline void Down()
{
y-=5;
if(y<MIN_HEIGHT) y=MIN_HEIGHT;
}
inline void Left()
{
x-=5;
if(x<MIN_WIDTH) y=MIN_WIDTH;
}
inline void Right()
{
x+=5;
if(x>MAX_WIDTH) y=MAX_WIDTH;
}
private:
int x;//橫坐標
int y;//縱坐標
ICON icon //角色圖標
};
class Player : public class Role
{
public:
Player()
{
SetICON();
}
};
class Thief : public class Role
{
public:
Player()
{
SetICON();
}
};

㈧ c語言程序設計——警察與小偷

#include <stdio.h>
#define true 1
#define false 0
#define I 9999 /* 無窮大 */
#define N 20 /* 城市頂點的數目 */

int cost[N][N] = {
{0,3,I,I,I,1,I,I,I,I,I,I,I,I,I,I,I,I,I,I},
{3,0,5,I,I,I,6,I,I,I,I,I,I,I,I,I,I,I,I,I},
{I,5,0,4,I,I,I,1,I,I,I,I,I,I,I,I,I,I,I,I},
{I,I,4,0,2,I,I,I,6,I,I,I,I,I,I,I,I,I,I,I},
{I,I,I,2,0,I,I,I,I,7,I,I,I,I,I,I,I,I,I,I},
{1,I,I,I,I,0,1,I,I,I,2,I,I,I,I,I,I,I,I,I},
{I,6,I,I,I,1,0,6,I,I,I,7,I,I,I,I,I,I,I,I},
{I,I,1,I,I,I,6,0,2,I,I,I,3,I,I,I,I,I,I,I},
{I,I,I,6,I,I,I,2,0,8,I,I,I,4,I,I,I,I,I,I},
{I,I,I,I,7,I,I,I,8,0,I,I,I,I,5,I,I,I,I,I},
{I,I,I,I,I,2,I,I,I,I,0,4,I,I,I,3,I,I,I,I},
{I,I,I,I,I,I,7,I,I,I,4,0,3,I,I,I,4,I,I,I},
{I,I,I,I,I,I,I,3,I,I,I,3,0,3,I,I,I,5,I,I},
{I,I,I,I,I,I,I,I,4,I,I,I,3,0,7,I,I,I,2,I},
{I,I,I,I,I,I,I,I,I,5,I,I,I,7,0,I,I,I,I,3},
{I,I,I,I,I,I,I,I,I,I,3,I,I,I,I,0,5,I,I,I},
{I,I,I,I,I,I,I,I,I,I,I,4,I,I,I,5,0,8,I,I},
{I,I,I,I,I,I,I,I,I,I,I,I,5,I,I,I,8,0,6,I},
{I,I,I,I,I,I,I,I,I,I,I,I,I,2,I,I,I,6,0,4},
{I,I,I,I,I,I,I,I,I,I,I,I,I,I,3,I,I,I,4,0}
};
int dist[N]; /* 存儲當前最短路徑長度 */
int v0 = 'A' - 65; /* 初始點是 A */

void main()
{
int final[N], i, v, w, min;

/* 初始化最短路徑長度數據,所有數據都不是最終數據 */
for (v = 0; v < N; v++) {
final[v] = false;
dist[v] = cost[v0][v];
}

/* 首先選v0到v0的距離一定最短,最終數據 */
final[v0] = true;

/* 尋找另外 N-1 個結點 */
for (i = 0; i < N-1; i++) {
min = I; /* 初始最短長度無窮大 */

/* 尋找最短的邊 */
for (w = 0; w < N; w++) {
if (!final[w] && dist[w] < min) {
min = dist[w];
v = w;
}
}
final[v] = true; /* 加入新邊 */

for (w = 0; w < N; w++) { /* 更新 dist[] 數據 */
if (!final[w] && dist[v] + cost[v][w] < dist[w]) {
dist[w] = dist[v] + cost[v][w];
}
}
}

for (i = 0; i < N; i++) { /* 顯示到監視器 */
printf("%c->%c: %2d\t", v0 + 65, i + 65, dist[i]);
}
}
這個應該夠大了