用map解决one to one关系
来源:互联网 发布:flow水刀软件 编辑:程序博客网 时间:2024/06/05 08:58
/*
(1)map函数表示的是映射的关系,其中下标相当于自变量,因此只能对应一个map的值
(2)对于判断关系是不是函数,可以用insert进行判断,注意insert(pair)以及返回的pair<map :: iterator , bool >类型
(3)one to one用加上y对x也只有一个
*/
#include <iostream>
#include <map>
using namespace std;
int main()
{
int T ;
cin >> T;
while(T --)
{
int flag = 1 , n , m , x , y;
map<int ,int> f , g;
pair< map<int , int> :: iterator , bool > temp1 , temp2;
cin >> n;
cin >> m;
for(int i = 0;i < m;i ++)
{
cin >> x;
cin >> y;
temp1 = f.insert(pair<int , int>(x,y));
temp2 = g.insert(pair<int , int>(y,x));
if(x > n || y > n || !temp1.second || !temp2.second)
flag = 0;
}
if(flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
(1)map函数表示的是映射的关系,其中下标相当于自变量,因此只能对应一个map的值
(2)对于判断关系是不是函数,可以用insert进行判断,注意insert(pair)以及返回的pair<map :: iterator , bool >类型
(3)one to one用加上y对x也只有一个
*/
#include <iostream>
#include <map>
using namespace std;
int main()
{
int T ;
cin >> T;
while(T --)
{
int flag = 1 , n , m , x , y;
map<int ,int> f , g;
pair< map<int , int> :: iterator , bool > temp1 , temp2;
cin >> n;
cin >> m;
for(int i = 0;i < m;i ++)
{
cin >> x;
cin >> y;
temp1 = f.insert(pair<int , int>(x,y));
temp2 = g.insert(pair<int , int>(y,x));
if(x > n || y > n || !temp1.second || !temp2.second)
flag = 0;
}
if(flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
阅读全文
0 0
- 用map解决one to one关系
- Nhibernate one-to-one 关系
- One-to-one关系映射
- Hibernate 一对一的关系(one-to-one)
- Hibernate one to one 关联关系映射
- Hibernate one to one映射关系
- 用我的MyGeneration模板生成NHibernate映射文件和关系(one-to-one,one-to-many,many-to-many)
- 用MyGeneration模板生成NHibernate映射文件和关系(one-to-one,one-to-many,many-to-many)
- Hibernate one-to-many / many-to-one关系映射
- Hibernate one-to-many / many-to-one关系映射
- hibernate连接sqlserver2000问题的解决(父子关系同时保存时发生 one-to-many & many-to-one)
- one to one
- Hibernate one-to-one
- hibernate :one-to-one
- 一对一 one-to-one
- hibernate:one-to-one
- one-to-one 映射
- one-to-one
- 【NOIP考前题目回顾】Luogu P1012
- 用实际例子理解回调函数(Calback)
- ubuntu 14.04 安装python工具包遇到的问题
- HDU4704 Sum
- 关于Apereo CAS中的几种timeout定义
- 用map解决one to one关系
- USB通讯协议
- CSS 内边距padding ,外边距margin
- 一个兼容所有浏览器的滑动固定导航--值得收藏
- 【学习记录】二分图染色
- Paint绘制文字
- 代码生成器
- 17.Oracle杂记——数据字典dba_ts_quotas
- 转换为不同灰度级图像