ACdream 群赛11.10 Problem J: I can't describe the problem
来源:互联网 发布:阿里云的机房 编辑:程序博客网 时间:2024/05/01 04:22
Problem J: I can't describe the problem
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 38 Solved: 5
[Submit][Status][Web Board]
Description
Input
Output
Sample Input
2 1 100 21 2 12
Sample Output
3 96
HINT
#include <cstdio>#include <cstring>#include <queue>#include <stack>#include <cmath>#include <algorithm>#include <iostream>using namespace std;const int N = 10009;struct TT{ int a,b,c; int nex;} re[10009];int FF[N],C=1;void FFadd(int v,int a,int b,int c){ re[C].a = a,re[C].b = b; re[C].c = c,re[C].nex = FF[v]; FF[v] = C++;}void init(){ memset(re,-1,sizeof(re)); for(int i=2;i<N;i++) for(int j=i;j<N;j++) { int t = i*i+j*j; int c = (int)sqrt(t); if(i+j+c>=N) break; if(c*c==t&&c>=j) { FFadd(i+j+c,i,j,c); } }}int n,m,p,T;struct LT{ int to,nex,dis,hp;} L[400009];int F[309],cnt;void add(int f,int t,int dis,int hp){ L[cnt].dis = dis,L[cnt].nex = F[f]; L[cnt].hp = hp;L[cnt].to =t; F[f] = cnt++;}struct nod{ int to,dis,hp; bool operator<(const nod t)const { return dis>t.dis||(dis==t.dis&&hp<t.hp); }};queue<nod> que;int in[309][109];int dis[309][109];const int INF = 0x3f3f3f3f;void solve(){ memset(dis,INF,sizeof(dis)); memset(in,0,sizeof(in)); while(!que.empty()) que.pop(); nod e,t; e.dis = 0,e.hp = p,e.to = 1; que.push(e); dis[1][p] = 0; while(!que.empty()) { e = que.front();que.pop(); in[e.to][e.hp] = 0; for(int i=F[e.to];i;i=L[i].nex) { int to = L[i].to; t.hp = e.hp - L[i].hp; t.to = to; if(t.hp<0) continue; if(dis[to][t.hp]<=e.dis+L[i].dis) continue; dis[to][t.hp] = dis[e.to][e.hp]+L[i].dis; t.dis = dis[to][t.hp]; if(!in[t.to][t.hp]) que.push(t); } } int mindis = INF,maxhp=-1; for(int i=0;i<=p;i++) if(dis[T][i]<=mindis) { mindis = dis[T][i]; maxhp = i; } if(mindis!=INF) { printf("%d %d\n",mindis,maxhp); return ; } printf("-1\n");}int main(){ freopen("in.txt","r",stdin); init(); while(~scanf("%d%d%d%d",&n,&m,&p,&T)) { memset(F,0,sizeof(F));cnt=1; int a,b,c; for(int i=0;i<m;i++) { scanf("%d%d%d",&a,&b,&c); add(a,b,c,0); for(int j=FF[c];j;j=re[j].nex) { add(a,b,re[j].a,(re[j].a%10)+1); add(a,b,re[j].b,(re[j].b%10)+1); add(a,b,re[j].c,(re[j].c%10)+1); } } solve(); } return 0;}
- ACdream 群赛11.10 Problem J: I can't describe the problem
- Problem J
- Problem J
- Problem J
- Problem-J
- Problem J
- Problem-J
- Problem J
- problem j
- Problem D & Problem J
- ACDream 1734 Can you make a water problem?(贪心)
- Can't set point Problem Solved!
- Virtual Memory I: the problem
- acdream 1414 Geometry Problem
- Solve the problem:Automation server can't create object in VS 2003
- The problem of “Can’t exit design mode because control ‘ShockwaveFlash1’ cannot be created.”
- Oh no! Something has gone wrong. A problem has ocurred and the system can't recover.
- VNC远程连接服务器出现 A problem has occurred and the system can't recover. 错误
- 从tfs优化看分布式存储系统
- 对生活现状的思考
- POJ 1087 A Plug for UNIX
- EthernetNative 和 android_net_ethernet.cpp
- 使用xmlHttpRequest实现Ajax技术
- ACdream 群赛11.10 Problem J: I can't describe the problem
- Hibernate_一对一双向外键关联
- Objective-C内存管理教程和原理剖析(二)口诀与范式
- 利用ffmpeg解码h264流的代码
- Objective-C内存管理教程和原理剖析(三)@property (retain)和@synthesize的默认实现
- 工作中应该持有的态度
- android ethernet
- 群赛11.10 A Very Easy Triangle Counting Game
- cocos2d-x内存管理机制