Problem K: Yikes -- Bikes!
http://acm.upc.edu.cn/problem.php?id=2780
昨天做的题,没过……!!!伤心……
题意:给你n个单位,n-1组关系,让你单位换算……
解题思路:Floyd算法
自己听别人说用Floyd算法,然后自己默默的用有向图写……但是!!!Floyd算法不能用有向图……!所以只能在其相反的转化中标记为负的,在进行时特殊处理一下,最后便利找出能进行单位转化的那组单位,然后进行大小排序,最后就莫名其妙的哦过了……!!!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <cctype>
#include <set>
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) typedef long long LL; using namespace std; int graph[][];
int c[];
int topo[];
int n;
int t;
struct Value{
int x,y;
}; bool cmp(Value a,Value b){
return a.x > b.x;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
map<string,int>un;
string name[];
while(cin >> n && n){
for(int i = ;i <= n;i++){
cin >> name[i];
un[ name[i] ] = i;
}
memset(graph,,sizeof(graph));
for(int i = ;i <= n-;i++){
string str1;
int num,a,b;
cin >> str1;
a = un[str1];
cin >> str1 >> num >> str1;
b = un[str1];
graph[a][b] = num;
graph[b][a] = - *num;
//cout <<a << " " << b << endl;
}
for(int k = ;k <= n;k++){
for(int i = ;i <= n;i++){
for(int j = ;j <= n;j++){
if(i == j || k == i || k == j)
continue;
if(!graph[i][j] &&graph[i][k] &&graph[k][j]){
if(graph[i][k] > && graph[k][j] > ){
graph[i][j] = graph[i][k] * graph[k][j];
graph[j][i] = - * graph[i][k] * graph[k][j];
}
else if(graph[i][k] < && graph[k][j] < ){
graph[j][i] = graph[i][k] * graph[k][j];
graph[i][j] = - * graph[i][k] * graph[k][j];
}
else if(graph[i][k] < && graph[k][j] > ){
if(abs(graph[i][k]) > graph[k][j]){
graph[j][i] = abs(graph[i][k]) / graph[k][j];
graph[i][j] = - * graph[j][i];
}
else{
graph[i][j] = abs(graph[i][k]) / graph[k][j];
graph[j][i] = - * graph[i][j];
}
}
else{
if(graph[i][k] > abs(graph[k][j])){
graph[i][j] = graph[i][k] / abs(graph[k][j]);
graph[j][i] = - * graph[i][j];
}
else{
graph[j][i] = graph[i][k] / abs(graph[k][j]);
graph[i][j] = - * graph[j][i];
}
}
}
}
}
}
int mark;
for(int i = ;i <= n;i++){
bool flag = ;;
for(int j = ;j <= n;j++){
if(graph[i][j] < ){
flag = ;
break;
}
}
if(flag){
mark = i;
break;
}
}
Value a[];
for(int i = ;i <= n;i++){
a[i-].x = graph[mark][i];
a[i-].y = i;
}
sort(a,a+n,cmp);
cout << << name[ a[n-].y ];
for(int i = n-;i > -;i--){
cout << " = "<< a[i].x << name[ a[i].y ] ;
}
cout << endl;
}
return ;
}
Problem K: Yikes -- Bikes!的更多相关文章
- Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...
- Codeforces 1089K - King Kog's Reception - [线段树][2018-2019 ICPC, NEERC, Northern Eurasia Finals Problem K]
题目链接:https://codeforces.com/contest/1089/problem/K time limit per test: 2 seconds memory limit per t ...
- Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]
题目链接:http://codeforces.com/gym/101981/problem/K Your friend has made a computer video game called “K ...
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem K. UTF-8 Decoder 模拟题
Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c702 ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力
Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...
- XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem K. Piecemaking
题目:Problem K. PiecemakingInput file: standard inputOutput file: standard outputTime limit: 1 secondM ...
- 2018 Multi-University Training Contest 4 Problem K. Expression in Memories 【模拟】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6342 Problem K. Expression in Memories Time Limit: 200 ...
- HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)
6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ...
- 华农oj Problem K: 负2进制【有技巧构造/待补】
Problem K: 负2进制 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 51 Solved: 6 [Submit][Status][Web Boa ...
随机推荐
- 乐观锁&悲观锁
悲观&乐观,只是对数据加锁的时机与粒度. 悲观锁(Pessimistic Lock), 顾名思义,就是很悲观,每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这 ...
- Java, C#, Swift语法对比速查表
原文:Java, C#, Swift语法对比速查表 Java 8 C# 6 Swift 变量 类型 变量名; 类型 变量名; var 变量名 : 类型; 变量(类型推断) N/A var 变量名= ...
- 为什么要选择cdn加速
CDN的通俗理解就是网站加速,CPU均衡负载,可以解决跨运营商,跨地区,服务器负载能力过低,带宽过少等带来的网站打开速度慢等问题. 比如: 1.一个企业的网站服务器在北京,运营商是电信,在广东的联通用 ...
- VC多线程编程
一.问题的提出 编写一个耗时的单线程程序: 新建一个基于对话框的应用程序SingleThread,在主对话框IDD_SINGLETHREAD_DIALOG添加一个按钮,ID为IDC_SLEEP_SIX ...
- Failed to retrieve procctx from ht. constr
给一个客户巡检时发生这样的少见的集群报错: [ OCRSRV][1220598112]th_select_handler: Failed to retrieve procctx from ht. c ...
- objective-C 初识
objective-C objective-c 是c语言的改进版 一.方法的定义: 格式: -/+(返回值类型)方法名:(参数类型) 参数名 [方法名] : (参数类型) 参数名......... 例 ...
- xp每天定时关机命令
at 00:00 /every:M,T,W,Th,F,S,Su shutdown -s -t 120 能够把00:00改成你想要每天定时关机的时间,120是指关机倒计时的秒数,也能够更改 M,T,W, ...
- 一、Python-----之变量
1.变量存在的意义就是在程序中存储一些临时的数据.2.程序运行的时候回调用变量的临时数据. 变量起名规则: 变量名只能是字符.数字或下划线的任意组合 变量名的第一个字符不能是数字 以下关键字不能声明为 ...
- 自定义类似QMutexLocker的CMutexLocker
最近做项目遇到一个需求,有一个buttonSlot()执行要耗点时间,为了防止用户无限制的乱点出现问题,考虑加一个互斥锁,使得每次执行完后才允许执行下一次.大概意思是: //QMutex m_mut ...
- Js内存泄露问题总结
最近接受了一个Js职位的面试,问了很多Js的高级特性,才发现长时间使用已知的特性进行开发而忽略了对这门语言循序渐进的理解,包括Java我想也是一样,偶尔在Sun官方看到JDK6.0列举出来的new f ...