当前位置: 首页 > news >正文

Foreign Exchange(UVA 10763)

网址如下:

Foreign Exchange - UVA 10763 - Virtual Judge (vjudge.net)

(第三方网站)

奇怪,很是奇怪

你可以看看题目的描述:

The program works out only if every student has a suitable exchange partner. In other words, if a student wants to go from A to B, there must be another student who wants to go from B to A.

这很明显表示的是必须每个人两两配对,而间接的交换是不行的:

1 到 2,2 到 3,3 到 1

但是这个网站的测试点是间接的方式也可以(我不是在UVA那刷题的,因为要翻墙)

最后是两个配对方式的都写了一遍

不能间接的代码如下:

#include<cstdio>
#include<map>
using namespace std;
struct exc{int A, B;bool operator<(const exc &tmp) const{return (A < tmp.A) ? true : ((A == tmp.A) ? B < tmp.B : false);}
};
void studInsert(const exc &m);
map<exc, int> students;int main(void)
{int n;while(scanf("%d", &n) == 1 && n){students.clear();for(int i = 0; i < n; i++){exc m;scanf("%d%d", &m.A, &m.B);studInsert(m);}if(students.empty()) printf("YES\n");else printf("NO\n");}return 0;
}
void studInsert(const exc &m)
{exc target{m.B, m.A};auto it = students.find(target);if(it != students.end() && --(it->second) == 0)students.erase(it);else{it = students.find(m);if(it != students.end()) (it->second)++;else students[m] = 1;}
}

可以不用像我用struct,直接用pair就可以了

能间接的代码如下:

#include<cstdio>
#include<cstring>
const int MAXNUM = 100000;
int location[MAXNUM];int main(void)
{int n;while(scanf("%d", &n) == 1 && n){memset(location, 0, sizeof(location));for(int i = 0; i < n; i++){int a, b;scanf("%d%d", &a, &b);location[a]--, location[b]++;}bool isJudege = true;for(int i = 0; i < MAXNUM; i++)if(location[i]){isJudege = false; printf("NO\n"); break;}if(isJudege) printf("YES\n");}return 0;
}

直接哈希表了

相关文章:

  • D2力扣滑动窗口系列
  • C++ inline关键字总结
  • C++读写Excel(xlnt库的使用)
  • 用一个 Python 脚本实现依次运行其他多个带 argparse 命令行参数的 .py 文件
  • CTP-API开发系列之三:柜台系统简介
  • RAG综述 《Retrieval-Augmented Generation for Large Language Models: A Survey》笔记
  • jupyter notebook 调整深色背景与单元格宽度与自动换行
  • 权限管理系统-0.2.0
  • 前端vite+vue3——可视化页面性能耗时指标(fmp、fp)
  • 蓝桥杯(3.10)
  • WPF 窗口添加投影效果Effect
  • 数据结构之八大排序
  • 数学建模-动态规划(美赛运用)
  • docker本地搭建spark yarn hive环境
  • Springboot+vue的医院药品管理系统(有报告)。Javaee项目,springboot vue前后端分离项目。
  • @angular/forms 源码解析之双向绑定
  • CSS魔法堂:Absolute Positioning就这个样
  • css系列之关于字体的事
  • golang中接口赋值与方法集
  • SwizzleMethod 黑魔法
  • Vue2.0 实现互斥
  • Web标准制定过程
  • 阿里中间件开源组件:Sentinel 0.2.0正式发布
  • 对象管理器(defineProperty)学习笔记
  • 模仿 Go Sort 排序接口实现的自定义排序
  • 微信如何实现自动跳转到用其他浏览器打开指定页面下载APP
  • 阿里云ACE认证学习知识点梳理
  • ​LeetCode解法汇总307. 区域和检索 - 数组可修改
  • ​云纳万物 · 数皆有言|2021 七牛云战略发布会启幕,邀您赴约
  • #FPGA(基础知识)
  • (14)目标检测_SSD训练代码基于pytorch搭建代码
  • (Git) gitignore基础使用
  • (LeetCode C++)盛最多水的容器
  • (Redis使用系列) Springboot 使用redis实现接口Api限流 十
  • (紀錄)[ASP.NET MVC][jQuery]-2 純手工打造屬於自己的 jQuery GridView (含完整程式碼下載)...
  • (十一)手动添加用户和文件的特殊权限
  • (转)h264中avc和flv数据的解析
  • (转)jQuery 基础
  • (转)Linq学习笔记
  • .gitignore
  • .NET 药厂业务系统 CPU爆高分析
  • .net最好用的JSON类Newtonsoft.Json获取多级数据SelectToken
  • /proc/stat文件详解(翻译)
  • [2019.2.28]BZOJ4033 [HAOI2015]树上染色
  • [Android] Amazon 的 android 音视频开发文档
  • [BZOJ1053][HAOI2007]反素数ant
  • [c#基础]DataTable的Select方法
  • [CISCN2019 华东南赛区]Web11
  • [C语言]一维数组二维数组的大小
  • [hdu 4552] 怪盗基德的挑战书
  • [JDBC-1] JDBC Base Template
  • [LeetCode][面试算法]逻辑闭环的二分查找代码思路
  • [LeetCode]Reverse Linked List II
  • [leetcode]Search a 2D Matrix @ Python
  • [LeetCode系列]3元素最近和问题的O(n^2)解法