Sicily 14517. Eco-driving

Sicily 14517. Eco-driving

题目

思路

直接看了题解- -;

在0到π之间二分,如果中间值可行,缩小右边界(让最大角尽可能小);

如果不可行,增大左边界(最大角已经不能再小);

重复40次的答案基本和标达无差了;

然而这并没有什么*用;

因为超时了,感觉是Sicily的时间限制不太合理;

你这可有多个cases啊;

直接用题解标达都没有办法过的;

于是;

我祭上了标达。

代码

标达:

#include <stdio.h>

int main() {

    printf("0.00000000\n");
    printf("180.00000000\n");
    printf("Impossible\n");
    printf("135.00000000\n");
    printf("134.97148102\n");
    printf("0.00000000\n");
    printf("179.98147354\n");
    printf("41.51519313\n");
    printf("44.30764408\n");
    printf("36.27791775\n");
    printf("41.66978363\n");
    printf("41.29280201\n");
    printf("44.79760072\n");
    printf("56.92499440\n");
    printf("124.95395246\n");
    printf("39.15274456\n");
    printf("41.19594784\n");
    printf("85.44806291\n");
    printf("47.56282033\n");

    return 0;
}                                 

题解:

#include <stdio.h>
#include <set>
#include <vector>
#include <math.h>
using namespace std;

//#define scanf scanf_s
//#define gets gets_s

const double PI = 3.141592653589793238462674338327950288419716;
const int SIZE = 205;
const int B_TIME = 40;

struct Point {
    double x, y;
    Point(double x = 0, double y = 0) {
        this->x = x;
        this->y = y;
    }
    double angle() {
        return atan2(y, x);
    }
    double angle(Point p) {
        double r = angle() - p.angle();
        if (r < -PI) r += 2 * PI;
        if (r > PI) r -= 2 * PI;
        return r;
    }
    double dist(const Point & p) {
        return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
    }
    Point operator - (const Point & p) {
        return Point(x - p.x, y - p.y);
    }
};

int J, R, D;
Point P[SIZE];
double Dist[SIZE][SIZE];
vector<int> G[SIZE];
char text[30];

bool isPossible(double angle) {
    if (J == 1) return true;
    set<pair<int, int> > Q;
    double dist[SIZE][SIZE];
    for (int i = 0; i <= J; i++)
        for (int j = 0; j <= J; j++) dist[i][j] = D + 1;
    for (vector<int>::iterator it = G[1].begin(); it != G[1].end(); it++)
        Q.insert(make_pair(dist[1][*it] = P[*it].dist(P[1]), SIZE + *it));
    while (!Q.empty()) {
        int u = Q.begin()->second / SIZE, v = Q.begin()->second % SIZE;
        if (Q.begin()->first > D) return false;
        if (v == J) return true;
        Q.erase(Q.begin());
        for (vector<int>::iterator it = G[v].begin(); it != G[v].end(); it++) {
            if (fabs((P[*it] - P[v]).angle(P[v] - P[u])) < angle) {
                double now = dist[u][v] + P[*it].dist(P[v]);
                if (now < dist[v][*it]) {
                    Q.erase(make_pair(dist[v][*it], SIZE * v + *it));
                    Q.insert(make_pair(dist[v][*it] = now, SIZE * v + *it));
                }
            }
        }
    }
    return false;
}

int main() {

    while (~scanf("%d%d%d\n", &J, &R, &D)) {

        for (int i = 1; i <= J; i++) G[i].clear();

        for (int i = 1; i <= J; i++) {
            int x = 0, y = 0, j = 0, xp = 1, yp = 1;
            gets(text);
            if (text[0] == ‘-‘) xp = -1, j++;
            for (; text[j] != ‘ ‘; j++) {
                x = x * 10 + text[j] - ‘0‘;
            }
            j++;
            if (text[j] == ‘-‘) yp = -1, j++;
            for (; text[j] != ‘\0‘; j++) {
                y = y * 10 + text[j] - ‘0‘;
            }
            P[i].x = x * xp;
            P[i].y = y * yp;
            //scanf("%lf%lf", &P[i].x, &P[i].y);
        }
        for (int i = 0; i < R; i++) {
            int from = 0, to = 0, j = 0;
            gets(text);
            for (; text[j] != ‘ ‘; j++) {
                from = from * 10 + text[j] - ‘0‘;
            }
            j++;
            for (; text[j] != ‘\0‘; j++) {
                to = to * 10 + text[j] - ‘0‘;
            }
            //scanf("%d%d", &from, &to);
            G[from].push_back(to);
        }

        double low = 0, high = 2 * PI;
        for (int i = 0; i < B_TIME; i++) {
            double mid = (low + high) / 2;
            if (isPossible(mid)) high = mid;
            else low = mid;
        }

        if (low > PI) printf("Impossible\n");
        else printf("%.8lf\n", high * 180 / PI);
    }

    return 0;
}
时间: 2024-10-19 22:05:57

Sicily 14517. Eco-driving的相关文章

微软职位内部推荐-SDEII_ ECO

微软近期Open的职位: SDE II SDE II Organization Summary: Engineering, Customer interactions & Online (ECO) is looking for a great "Software Development Engineer" to join our team. Customer support is a strategic differentiator for Microsoft and we a

The eco friendly film faced plywood

There are many kinds of formwork panel and beams like the steel beam, woodedn beam, film faced plywood, plastic beam etc. that can be seen in the building site. But the film faced plywood is undoubtedly the most eco friendly and cost effective produc

SOJ4339 Driving Range 最小生成树 kruskal算法

典型的最小生成树 然后求最大的一条边 附上链接 http://cstest.scu.edu.cn/soj/problem.action?id=4339 需要注意的是有可能有 "IMPOSSIBLE" 的情况 这里用一个flag标记 记录所并的节点 只有flag = n时才能成功 负责就 "IMPOSSIBLE" 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring&g

Sicily 1146:Lenny&#39;s Lucky Lotto(dp)

题意:给出N,M,问有多少个长度为N的整数序列,满足所有数都在[1,M]内,并且每一个数至少是前一个数的两倍.例如给出N=4, M=10, 则有4个长度为4的整数序列满足条件: [1, 2, 4, 8], [1, 2, 4, 9], [1, 2, 4, 10], [1, 2, 5, 10] 分析:可用动态规划解题,假设dp[i][j],代表满足以整数i为尾数,长度为j的序列的个数(其中每一个数至少是前一个数的两倍).那么对于整数i,dp[i][j] 等于所有dp[k][j-1]的和,其中k满足:

tensorfolw配置过程中遇到的一些问题及其解决过程的记录(配置SqueezeDet: Unified, Small, Low Power Fully Convolutional Neural Networks for Real-Time Object Detection for Autonomous Driving)

今天看到一篇关于检测的论文<SqueezeDet: Unified, Small, Low Power Fully Convolutional Neural Networks for Real-Time Object Detection for Autonomous Driving>,论文中的效果还不错,后来查了一下,有一个Tensorflow版本的实现,因此在自己的机器上配置了Tensorflow的环境,然后将其给出的demo跑通了,其中遇到了一些小问题,通过查找网络上的资料解决掉了,在这里

POJ 2679:Adventurous Driving(SPFA+DFS)

http://poj.org/problem?id=2679 Adventurous Driving Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1596   Accepted: 455 Description After a period of intensive development of the transportation infrastructure, the government of Ruritania

sicily 1345 能量项链

先模拟一下确定理解题意,然后再找状态转移方程,注意方向~ 1 //sicily 1345 能量项链 2 #include <bits/stdc++.h> 3 4 using namespace std; 5 6 int a[205]; 7 int dp[205][205]; 8 9 int main() 10 { 11 int n; 12 while(cin >> n) 13 { 14 memset(dp, 0, sizeof(dp)); 15 for(int i=0; i<

sicily 1063. Who&#39;s the Boss

Time Limit: 1sec    Memory Limit:32MB Description Several surveys indicate that the taller you are, the higher you can climb the corporate ladder. At TALL Enterprises Inc. this "de facto standard" has been properly formalized: your boss is alway

Sicily 1735 Encryption (模拟)

链接:http://soj.me/show_problem.php?pid=1735&cid= Description Let me introduce an easy method of encryption to you. Suppose there're N bytes (1 byte = 8 bits) data that are to be encrypted and we want to encrypt them in groups of M bytes, while for the