#28370: WA (line:5),請問我的問題,謝謝


hslin@mail.hhsh.chc.edu.tw (AC)

學校 : 國立溪湖高級中學
編號 : 82903
來源 : [111.253.0.149]
最後登入時間 :
2023-12-18 12:06:05
e464. 神奇石頭 | From: [114.42.219.222] | 發表日期 : 2021-12-05 17:20

#include <iostream>

using namespace std;

#include <cmath>

#include <set>

int main() {

ios_base::sync_with_stdio(0);

    cin.tie(0);

 

int r,n,k;

while(1){

cin >> r >> n;

if (r==-1 && n==-1) break;

 

set<int> a;

set<int>::iterator it;

 

for(int j=0;j<n;j++){

cin >> k;

a.insert(k);

}

int t = *a.begin(),s=1;

 

for(it = a.begin();it!=a.end();it++){

if (abs(*it-t)<=r) continue;

else{

s++;

t = *it; 

}

}

 

cout << s << "\n";

}

}

 
#28385: Re:WA (line:5),請問我的問題,謝謝


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
e464. 神奇石頭 | From: [39.9.68.65] | 發表日期 : 2021-12-06 19:35

#include

using namespace std;

#include

#include

int main() {

ios_base::sync_with_stdio(0);

    cin.tie(0);

 

int r,n,k;

while(1){

cin >> r >> n;

if (r==-1 && n==-1) break;

 

set a;

set::iterator it;

 

for(int j=0;j<n;j++){

cin >> k;

a.insert(k);

}

int t = *a.begin(),s=1;

 

for(it = a.begin();it!=a.end();it++){

if (abs(*it-t)<=r) continue;

else{

s++;

t = *it; 

}

}

 

cout << s << "\n";

}

}


我猜是因為你只有判斷石頭之前的士兵,忽略石頭後的士兵也在半徑內。

例如測資是

2 3

2 4 6

輸出應該是1(石頭在4的位置)

 
ZeroJudge Forum