0

這題怎麼做，求大神幫忙!

(1 < N、M <10000)

7 4
3 1 5 7
6 6
6 1 3 2 5 4
6 8
6 1 1 1 2 5 2 5

2 4 6
@
3 4

dragonH iT邦超人 5 級 ‧ 2020-05-18 09:51:52 檢舉

pinglam iT邦新手 5 級 ‧ 2020-05-18 10:26:04 檢舉

https://en.wikipedia.org/wiki/Z1_(computer)
1938年德國的電腦

@一級屠豬士

http://course.lksh.ntpc.edu.tw/ShowProblem?problemid=W053

4 個回答

2
yu2001
iT邦新手 5 級 ‧ 2020-05-19 20:28:31

``````#include <iostream>
using namespace std;

int main()
{
int n,m,tmp;
for (;cin >> n >> m;)
{
int arr[10001]{0};
int flag=0;
for (int i = 0; i < m;++i)
{
cin >> tmp;
arr[tmp] = 1;
}
for (int i = 1;i<=n;++i)
{
if(!arr[i])
{
cout << i << " ";
flag = 1;
}
}
cout<<(flag?"\n":"@\n");
}

}
``````

yu2001 iT邦新手 5 級 ‧ 2020-05-20 11:09:37 檢舉

10

iT邦大師 1 級 ‧ 2020-05-18 13:29:32

``````#!/usr/bin/env python3

counter = 0

with open('ithelp200518_testdata.txt') as fin:
for line in fin:
counter = counter + 1
splst = line.split()
if counter % 2 == 1:
n = int(splst[0])
m = int(splst[1])
else:
if n == m:
print('@')
else:
soldierlst = line.split()
soldierlst = list(map(int, soldierlst))
soldierset = set(soldierlst)
stupidset = set([x for x in range(1, n+1)])
difflst = list(stupidset - soldierset)
print(*difflst)
``````

e6319a5b iT邦新手 5 級 ‧ 2020-05-24 14:45:43 檢舉

``````import random
n=6
m=6
member=[random.randint(1,m) for i in range(n) ]
print(member)

if n == m:
print('@')
else:
soldierlst = member
soldierlst = list(map(int, soldierlst))
soldierset = set(soldierlst)
stupidset = set([x for x in range(1, n+1)])
difflst = list(stupidset - soldierset)
print(*difflst)
``````

[6, 5, 4, 2, 2, 5]
{1, 3}//正解
@ //您的輸出

e6319a5b iT邦新手 5 級 ‧ 2020-05-24 15:13:09 檢舉

e6319a5b iT邦新手 5 級 ‧ 2020-05-24 15:27:15 檢舉

e6319a5b
[6, 5, 4, 2, 2, 5]

e6319a5b iT邦新手 5 級 ‧ 2020-05-27 15:29:25 檢舉

@ted59438 直接用差集就好了

KYC iT邦新手 4 級 ‧ 2020-05-31 02:22:35 檢舉

hints
if list not in [X] 檢查沒有在隊列裡的士兵
print("The current surviving soldier number is %s" % yourlist[0])

2

iT邦大神 1 級 ‧ 2020-05-19 08:54:07

0
e6319a5b
iT邦新手 5 級 ‧ 2020-05-24 14:46:34
``````import random
n=6
m=6

member=[random.randint(1,n) for i in range(m) ]
print(member)
#member=[6,1,3,2,5,4]
lists=[]
for i in range(m):
lists.append(member[i])

numbers=range(1,n+1)
a=set(numbers).difference(lists)
if(a==set()):
print('@')
else:
print(a)

``````