#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
long long int x1, y1, x2, y2, r;
while(cin >> x1 >> y1 >> x2 >> y2 >> r)
{
if(x2<x1)
{
long long int t=x2;
x2=x1;
x1=t;
}
if(y2<y1)
{
long long int s=y2;
y2=y1;
y1=s;
}
if(x2-x1+y2-y1>r)
cout << "alive" << endl;
else
cout << "die" << endl;
}
//system("PAUSE");
return EXIT_SUCCESS;
}
上面是我的程式
第9個測資會TLE
是我運算法有問題
還是測資有特別之處?
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
long long int x1, y1, x2, y2, r;
while(cin >> x1 >> y1 >> x2 >> y2 >> r)
{
if(x2 {
long long int t=x2;
x2=x1;
x1=t;
}
if(y2 {
long long int s=y2;
y2=y1;
y1=s;
}
if(x2-x1+y2-y1>r)
cout << "alive" << endl;
else
cout << "die" << endl;
}
//system("PAUSE");
return EXIT_SUCCESS;
}
上面是我的程式
第9個測資會TLE
是我運算法有問題
還是測資有特別之處?
我跟朋友也都過不了
複雜度不是才O(1)....
Hmm...
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
long long int x1, y1, x2, y2, r;
while(cin >> x1 >> y1 >> x2 >> y2 >> r)
{
if(x2 {
long long int t=x2;
x2=x1;
x1=t;
}
if(y2 {
long long int s=y2;
y2=y1;
y1=s;
}
if(x2-x1+y2-y1>r)
cout << "alive" << endl;
else
cout << "die" << endl;
}
//system("PAUSE");
return EXIT_SUCCESS;
}
上面是我的程式
第9個測資會TLE
是我運算法有問題
還是測資有特別之處?
過了.. 還刷掉最佳解17ms(51ms->34ms)
第9個測資scanf+printf 9XXms (快爆掉)
要優化輸入..
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
long long int x1, y1, x2, y2, r;
while(cin >> x1 >> y1 >> x2 >> y2 >> r)
{
if(x2 {
long long int t=x2;
x2=x1;
x1=t;
}
if(y2 {
long long int s=y2;
y2=y1;
y1=s;
}
if(x2-x1+y2-y1>r)
cout << "alive" << endl;
else
cout << "die" << endl;
}
//system("PAUSE");
return EXIT_SUCCESS;
}
上面是我的程式
第9個測資會TLE
是我運算法有問題
還是測資有特別之處?
過了.. 還刷掉最佳解17ms(51ms->34ms)
第9個測資scanf+printf 9XXms (快爆掉)
要優化輸入..
#include <iostream>
using namespace std;
int main(){
long long int x1, y1, x2, y2, r, k = 1;
while (cin >> x1 >> y1 >> x2 >> y2 >> r){
for (int i = 0; i < 2; i++){
if (abs(x2 - x1) > r || abs(y2 - y1) > r){//若x或y直線距離超過r則直接跳出for k=0 不損毀首都
k = 0;
}
else if (x1 < x2 && (x2 - x1) <= r){//首都在天譴中心右側
r = r - (x2 - x1);
x1 = x2;
}
else if (x1 > x2 && (x1 - x2) <= r){//首都在天譴中心左側
r = r - (x1 - x2);
x1 = x2;
}
else if (x1 == x2){//首都在天譴中心 Y軸上
if (y1 < y2 && (y1 - y2) <= r){//首都在天譴中心上方
r = r - (y1 - y2);
y1 = y2;
k = 1;
}
else if (y1 > y2 && (y1 - y2) <= r){//首都在天譴中心下方
r = r - (y1 - y2);
y1 = y2;
k = 1;
}
y1 == y2 ? k = 1 : k = 0;
}
else{
k = 0;
}
}
k == 1 ? cout << "die" << endl : cout << "alive" << endl;
k = 1;
}
return 0;
}
我也是過不了...
第九項是藏了什麼RRRR