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 ...
随机推荐
- USACO Barn Repair 【贪心算法】
这到题目的题意不太好理解= = 看来还是英语太弱了 实际上题目给了你M, S, C 分别代表最多不超过M 块木板, S代表牛棚总数,C代表接下来有C个牛所在牛棚的标号 然后求的是如何安排方案,可以使得 ...
- weblogic公布的项目用途myeclipse正常启动,点击startWeblogic.cmd报错解决方案
今天在做项目中遇到的问题.使用weblogic公布的项目,使用myeclipse正常启动,但点击startWeblogic.cmd会报错.我提出了一个class not found.楚是什么问题.后来 ...
- 【LeetCode】Repeated DNA Sequences 解题报告
[题目] All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...
- SQL查询重复记录、删除重复记录方法
查找所有重复标题的记录:SELECT * FROM t_info a WHERE ((SELECT COUNT(*) FROM t_info WHERE Title = a.Title) > 1 ...
- C++多态原理
C++的多态性是通过动态绑定实现的 非虚函数是在编译时绑定的; 通过对象进行的函数(虚函数,非虚函数)也是编译时绑定的; C++编译器在编译的时候,要确定每个对象调用的函数(要求此函数是非虚函数)的地 ...
- CentOS 漏洞修补
以前没注意 今后得实时更新系统漏洞和补丁了! 1.Bash软件安全漏洞检测及解决方案 http://netsecurity.51cto.com/art/201409/452322.htm
- centos安装python gcc sqlite
终端中输入命令:yum install gcc -y yum install python -y yum install sqlite -y
- 基于visual Studio2013解决C语言竞赛题之0702函数设计
题目
- 初探 FFT/DFT
有用的学习链接&书籍 傅立叶变化-维基百科 离散傅立叶变化-维基百科·长整数与多项式乘法 维基百科看英文的更多内容&有趣的图 快速傅立叶变化-百度百科,注意其中的图! 组合数学(第4版 ...
- POJ 2112 Optimal Milking (二分+最短路径+网络流)
POJ 2112 Optimal Milking (二分+最短路径+网络流) Optimal Milking Time Limit: 2000MS Memory Limit: 30000K To ...