下面这个例子就是 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. HTML+CSS笔记 CSS入门

    简介: </span>年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的<span>脚本解释程序</span>,作为ABC语言的一种继承. & ...

  2. PowerShell Remove all user defined variable in PowerShell

    When PS scripts executes, it is possibly create much user defined variables. So, sometimes these var ...

  3. PROTEL 99SE的打印设置

    现在市面上关于PTROTEL99SE的书很多,但都没有具体叙述有关电路图的打印设置方法.PROTEL99SE的打印设置较之以前的版本有了很多不同之处.特别是在实际做电路板时有些细节须注意. 原理图的打 ...

  4. CI引入外部javascript和css

    假定baseurl 为 $config['base_url']='http://localhost/codeigniter/'; 调用 <link rel="stylesheet&qu ...

  5. Zookeeper 在Hadoop中的应用

    Zookeeper 简单介绍 Zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目.它主要是用来解决分布式应用中常常遇到的一些数据管理问题,如:统一命名服务.状态同步服务.集 ...

  6. mybatis级联查询

    1.定义四个实体.User   Role    Privilege   Resource,他们之间的对于关系为 2.需求:我通过用户名username查找出该用户对应的角色以及角色对应的权限和资源 3 ...

  7. DevExpress ASP.NET 使用经验谈(7)-ASPxTreeList控件使用

    这一节,将介绍ASPxTreeList控件的使用,首先,我们增加一个标准地址库表AddressGB, 建表语句如下: CREATE TABLE [dbo].[AddressGB]( [Code] [v ...

  8. 【原】Spring和Dubbo整合案例和过程

    Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,Dubbo采用的是一种非常简单的模 ...

  9. POJ 1458 Common Subsequence(LCS最长公共子序列)

    POJ 1458 Common Subsequence(LCS最长公共子序列)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  10. Main function

    Main function A program shall contain a global function named main, which is the designated start of ...