Warm up 16 Texas Summers
| Texas Summers |
| Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB |
| Total submit users: 17, Accepted users: 12 |
| Problem 12783 : No special judgement |
|
Problem description 哎,算了这题就当自己对了吧,一直找不到错误,一直WA,真的很神奇!撸过的大牛你能找到?居然做这种事,当自己对了,我还有什么用额! |
| Summer in Texas can be very hot. But Texans are tough, and in a weird way some of them enjoy the heat; for even he heat is bigger in Texas. But the heat can be quite uncomfortable for computer science students who are new to Texas and are not used to the sweating it can cause. These students want to minimize the amount they sweat while walking from their dormitory to class. When they enter the sunshine, they begin sweating. The longer they stay in the sun, the more they sweat. The amount they sweat s proportional to the square of how long they have been continuously exposed to the sun. Put another way, if they are in the sun continuously for s seconds, they will sweat Cs2 gallons, where C is a constant which is different for different students. But if they find a shady spot along the way, their continuous sun exposure is broken and they stop weating immediately. They can then sit in the shade and cool off completely before continuing on their journey to class. Of course, leaving the shade means they begin sweating again. Write a program that helps a student find a path from the dormitory to class which minimizes the total amount of weat she expends. |
| Input |
| Input describes the locations of shady spots on campus as well as the student’s dormitory and class locations. Input begins with a line containing an integer 0 ≤ n ≤ 2500, the number of shady spots. Each of the next n lines contains a pair of integers x y specifying the coordinates of a shady spot. No two shady spots have the same coordinates. Following the shady spots are two more lines in the same format which specify the coordinates of the student’s dormitory and class, respectively. |
| Output |
| Print a path the student can take to get from her dormitory to class. The path should minimize the total sweat produced along the whole path. Print the path as indexes of the shady spots (from the order given in the input, with the first shady spot having index 0). If the best path contains no shady spots, output a single ‘-’. If there are multiple paths that minimize the total sweat, print any one of them. |
| Sample Input |
Sample Input 1 3 1 1 2 -2 5 -1 0 0 9 0 Sample Input 2 6 8 2 4 0 8 0 4 -1 7 -1 6 -2 2 1 9 2 Sample Input 3 1 -5 -5 0 0 10 10 |
| Sample Output |
Sample Output 1 1 2 Sample Output 2 1 3 5 4 2 Sample Output 3 - |
| Problem Source |
| NAQC 2012 |
| Submit Discuss Judge Status Problems Ranklist |
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cmath> 7 #include <cstdio> 8 #include <cstring> 9 #include <cstdlib> 10 #include <iostream> 11 #include <algorithm> 12 using namespace std; 13 #define maxn 2555 14 #define ll __int64 15 #define mod 1000000007 16 #define INF 0x7fffffff 17 #define eps 1e-8 18 int n, m, s, t; 19 struct Heap{ 20 ll d; 21 int u; 22 Heap(ll a,int b){d=a,u=b;} 23 bool operator<(const Heap& cmp)const{ 24 return d>cmp.d; 25 } 26 }; 27 int vis[maxn],p[maxn]; 28 ll d[maxn],a[maxn],b[maxn]; 29 void init(){ 30 for (int i = 0; i<= 2505; i++)d[i] = -1; 31 memset(vis,0,sizeof vis); 32 } 33 void dijkstra(int s){ 34 priority_queue<Heap>q; 35 while(!q.empty())q.pop(); 36 d[s] = 0; 37 q.push(Heap( d[s], s )); 38 while (!q.empty()){ 39 Heap x = q.top(); q.pop(); 40 int u = x.u; 41 if(vis[t])return; 42 if(vis[u])continue; 43 vis[u]=1; 44 for (int i = 0; i<n+2; i++){ 45 int v = i; 46 ll x = (a[u] - a[v])*(a[u] - a[v]) + (b[u] - b[v])*(b[u] - b[v]); 47 if (!vis[v]&&(d[v]==-1||d[v]>d[u] + x)){ 48 d[v] = d[u] + x; 49 p[v] = u; 50 q.push(Heap( d[v], v )); 51 } 52 } 53 } 54 } 55 void print(int u){ 56 if (p[u] != s)print(p[u]); 57 printf("%d\n", u); 58 } 59 int main(){ 60 while (scanf("%d", &n)!=EOF){ 61 init(); 62 for (int i = 0; i < n+2; i++) 63 scanf("%I64d%I64d", &a[i], &b[i]); 64 //if(n==0||(a[n]==a[n+1]&&b[n]==b[n+1])){printf("-\n");continue;} 65 s = n; t = n + 1; 66 dijkstra(s); 67 if (p[t] == s)printf("-\n"); 68 else print(p[t]); 69 } 70 return 0; 71 }
浙公网安备 33010602011771号