下面这个例子就是 STL:pair 的用法

#include <iostream>
#include <utility>
#include <string>
using namespace std; int main () {
pair <string,double> product1 ("tomatoes",3.25);
pair <string,double> product2;
pair <string,double> product3; product2.first = "lightbulbs"; // type of first is string
product2.second = 0.99; // type of second is double product3 = make_pair ("shoes",20.0); cout << "The price of " << product1.first << " is $" << product1.second << "\n";
cout << "The price of " << product2.first << " is $" << product2.second << "\n";
cout << "The price of " << product3.first << " is $" << product3.second << "\n";
return 0;
}

这道题目使用 pair 可以非常方便的解决

Source Code:

 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ; map <string,int> mp;
map < pair<int,int>,int > G;
vector <string> a[];
int b[];
string str[], tmp; int main() {
int i, j, t, n, m, k, q;
scanf("%d",&t);
while (t--) {
scanf("%d %d %d",&n,&m,&q);
mp.clear();
G.clear();
for (i = ; i < n + m; ++i) {
a[i].clear();
cin >> tmp;
mp[tmp] = i;
cin >> k;
for (j = ; j < k; ++j) {
cin >> tmp;
a[i].push_back(tmp);
}
}
for (i = ; i < n + m; ++i)
for (j = ; j < a[i].size(); ++j)
G[make_pair (i,mp[a[i][j]])] = ;
while (q--) {
cin >> k;
for (i = ; i < k; ++i) {
cin >> tmp;
str[i] = tmp;
b[i] = mp[str[i]];
}
int flag;
for (i = ; i < k; ++i) {
flag = ;
for (j = ; j < k; ++j) {
if (i != j) {
if ( G[ make_pair(b[i],b[j]) ] == || G[ make_pair(b[j],b[i]) ] == ) {
flag = ;
break;
}
}
}
if (flag) {
cout << "1 " << str[i] << endl;
break;
}
}
if (!flag) cout << << endl;
}
cout << endl;
}
return ;
}

  

ZOJ 3601 Unrequited Love 【STL__pair_的应用】的更多相关文章

  1. ZOJ 3601 Unrequited Love 浙江省第九届省赛

    Unrequited Love Time Limit: 16 Seconds      Memory Limit: 131072 KB There are n single boys and m si ...

  2. zjuoj 3601 Unrequited Love

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3601 Unrequited Love Time Limit: 16 Sec ...

  3. zoj 3601

    链接 [https://vjudge.net/contest/293343#problem/B] 题意 就是n男m女.然后给出他们喜欢那些人 再给出q次询问 每次参加party的人 让你找出某个人满足 ...

  4. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  5. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  6. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  7. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  8. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  9. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

随机推荐

  1. isinstance 和 issubclass

    一.isinstance Python 中的isinstance函数 isinstance是Python中的一个内建函数 语法: isinstance(object, classinfo) 如果参数o ...

  2. Eclipse运行慢

    http://blog.csdn.net/chrissata/article/details/7759836 http://blog.csdn.net/heyutao007/article/detai ...

  3. QT小技巧—更好管理项目(增加预编译头文件,并且指定moc文件的生成位置)good

    预编译加速编译 QT也可以像VS那样使用预编译头文件来加速编译器的编译速度.首先在.pro文件中加入: CONFIG += precompiled_header 然后定义需要预编译的头文件: PREC ...

  4. JAVA FILE or I/O学习 - I/O流操作:FileInputStream、FileOutputStream、ObjectInputStream、ObjectOutputStream、InputStreamReader、OutputStreamWriter等

    public class IOStreamKnow { /*********************************文件读写方式:字节流**************************** ...

  5. 双网卡绑定(suse)

    网卡绑定技术有助于保证高可用性特性并提供其它优势以提高网络性能,Linux双网卡绑定实现就是使用两块网卡虚拟成为一块网卡,这个聚合起来的设备看起来是一个单独的以太网接口设备,就是两块网卡具有相同的IP ...

  6. Shortest Prefixes(trie树唯一标识)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15948   Accepted: 688 ...

  7. java代码发送JSON格式的httpPOST请求

    package com.test; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOE ...

  8. Spring MVC遭遇checkbox的问题解决方式

    Spring MVC遭遇checkbox的问题是:当checkbox全不选时候,则该checkbox域的变量为null,不能动态绑定到spring的controller方法的入參上,并抛出异常. 解决 ...

  9. Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型

    Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型 在这一节中,你将添加用于管理数据库中电影的类.这些类是ASP.NET MVC应用程序的模型部分. 你将使用.NET Framewo ...

  10. 设计模式值六大原则——依赖倒置原则 (DIP)

    依赖倒置原则(Dependence Inversion Principle,DIP)的原始定义: 高层模块不应该依赖底层模块,两者都应该依赖其抽象: 抽象不应该依赖细节: 细节应该依赖抽象. 依赖倒置 ...