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. (Problem 15)Lattice paths

    Starting in the top left corner of a 22 grid, and only being able to move to the right and down, the ...

  2. emoji表情键盘 回退删除方法

  3. Android ImageView(scaleType属性)图片按比例缩放

    <ImageView android:id="@+id/img" android:src="@drawable/logo" android:scaleTy ...

  4. Python 2.7 学习笔记 基本语法和函数定义

    本文介绍下python的基本语法 一.变量定义 不需要说明类型,也不需要像js等脚本语言使用var等标识符.直接声明即可,如: num=1 说明:上面语句声明了一个变量num,并在声明时初始化值为 1 ...

  5. C++sort函数使用总结

    头文件:algorithm 对于(整数/字符)数组进行比較时,可直接通过sort(a,a+n)或sort(a.begin(),a.end())进行排序,默认升序排列,须要高速实现降序时,有三种方案 1 ...

  6. Linux之shell编程基础

    一.变量 变量在shell中分为:本地变量.环境变量.位置参数: 本地变量:仅可在用户当前shell生命期的脚本中使用的变量,本地变量随着shell进程的消亡而无效,本地变量在新启动的shell中依旧 ...

  7. android:android:background="#00000000",透明效果

    ImageButton中设置 android:background="#00000000",可以达到透明效果 具体的源码 管理-->文件中的 viewpager0829.ra ...

  8. InputStream中read()与read(byte[] b)

    原文:InputStream中read()与read(byte[] b) read()与read(byte[] b)这两个方法在抽象类InputStream中前者是作为抽象方法存在的,后者不是,JDK ...

  9. mysql各版本区别

    MySQL 的官网下载地址:http://www.mysql.com/downloads/ 在这个下载界面会有几个版本的选择. 1. MySQL Community Server 社区版本,开源免费, ...

  10. 基于Andoird 4.2.2的Account Manager源代码分析学习:AccountManagerService系统服务的添加

    从启动说起 Android系统加载时,首先启动init进程,该进程会启动Zygote进程.Zygote进程执行/system/bin/app_process程序.app_process程序在执行中,通 ...