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!的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)

    6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ...

  9. 华农oj Problem K: 负2进制【有技巧构造/待补】

    Problem K: 负2进制 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 51 Solved: 6 [Submit][Status][Web Boa ...

随机推荐

  1. android Listview,gridview局部刷新,部分刷新

    众所周知Listview和Gridview的刷新界面的方式是调用adapter.notifyDataSetChanged()进行界面刷新. 但是此方法有其弊端,他是将界面中的数据全部刷新一遍,不论数据 ...

  2. Axis2(10):使用soapmonitor模块监视soap请求与响应消息

    在Axis2中提供了一个Axis2模块(soapmonitor),该模块实现了与<WebService大讲堂之Axis2(9):编写Axis2模块(Module)>中实现的logging模 ...

  3. Vi/VIM键盘图, Vi/vim学习图

    Vi/vim学习图 引用: Vi键盘图片可视化教程 http://www.cnblogs.com/me115/archive/2010/11/16/1878295.html 网上的文章易流失.感谢分享 ...

  4. 1 #安装php

    #安装php #备注:php5..3以后的版本源码不需要打php-fpm补丁,该补丁已经集成进5..3中强制启用fastcgi. [root@dba01 nginx-]# cd [root@dba01 ...

  5. Java正则表达式基本应用

    一.概述 正则表达式因为其强大的字符串处理能力,刚开始被被广泛地应用到各种UNIX工具中,如大家熟知的 Perl脚本语言 .后来正则表达式在各种 计算机语言 和各种应用领域得到了广泛的应用和发展,目前 ...

  6. 深入浅出单实例Singleton设计模式

    深入浅出单实例Singleton设计模式 陈皓 单实例Singleton设计模式可能是被讨论和使用的最广泛的一个设计模式了,这可能也是面试中问得最多的一个设计模式了.这个设计模式主要目的是想在整个系统 ...

  7. vim: 搭建vim看代码的环境

    使用 vim + ctags + cscope + taglist 阅读源码  http://my.oschina.net/u/554995/blog/59927 vim tab变空格 http:// ...

  8. javascript每日一练(三)——DOM一

    一.Dom基础 childNodes(有兼容问题),children nodeType getAttribute() firstChild,lastChild,previousSilbing,next ...

  9. USB基础简介

    一.USB2.0 Universal Serial Bus (通用串行总线)  符合USB总线数据通信要求的通信协议 1.意义 1.易用(热插拔.即插即用) 2.易扩充(USBHub可同时操作127个 ...

  10. boost uuid

    uuid: uuid库是一个小的使用工具,可以表示和生成UUID UUID是University Unique Identifier的缩写,它是一个128位的数字(16字节),不需要有一个中央认证机构 ...