【模拟】Thanks, TuSimple!

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5979

Thanks, TuSimple!

Time Limit: 1 Second Memory Limit: 65536 KB

In the very first sentence of the very first problem, we would like to give our sincere thanks to TuSimple, the sponsor of this contest.

Founded in 2015, TuSimple is a global autonomous trucking solution company headquartered in San Diego, operating self-driving trucks out of Tucson, Arizona. TuSimple is now developing a commercial-ready Level 4 (SAE) fully-autonomous driving solution for the logistics industry. TuSimple’s trucks are the first and only capable of self-driving from depot-to-depot and do so every day for its customers. The company is driven by a mission to increase safety, decrease transportation costs, and reduce carbon emissions.

Nowadays, the trucking industry is currently facing a shortage of 50000 drivers (which is expected to increase to 175000 by the end of 2024) and is approaching a 100 percent turnover rate per year with an average driver age of 49 years old. According to a PwC study, autonomous trucking technologies will reduce annual operating costs for a traditional average long-haul truck by 28 percent in 2025. TuSimple is aiming to transform the 740-billion U.S. trucking industry by cutting costs, reducing carbon emissions and eradicating some of the challenges currently faced by operators.

Building the industry’s first 1000-meter perception system, TuSimple soon becomes the pioneer in the industry. As is known to us, 1000 meters can provide 35 seconds of reaction time on average at highway speeds, enabling the system to make the safest and most efficient driving decisions. Even in the adverse weather conditions, the perception system is still designed to identify objects and obstacles, ensuring the safety of both cargoes, trucks, and passers-by. On the other hand, TuSimple’s latest proprietary AI is now capable of long-distance highway driving and complex surface street driving, which allows fully autonomous deliveries from one depot to another.

Despite their advanced technology and an enormous sense of mission in the industry, TuSimple shares the corporate culture of honesty, realistic, exploration and innovation among their employees from bottom to top, which allows them to attract more and more elites from all expertise to join and get involved. “Here’s why a little-known autonomous trucking company is beating Tesla and Waymo in the race for driverless big rigs”, commented by Business Insider.
The future of trucking is now!

As a manager of TuSimple, you are going to hold a dancing party for both the Development Department and the Marketing Department. There will be gentlemen and ladies in total and they are going to dance in pairs. After a careful investigation, we have already known that for each person, they like to dance with either a taller person or a person with smaller height. To simplify the problem, there are no two persons of the same height and people are only allowed to dance with a person of the opposite gender. In order to reserve a proper dancing field, you must calculate the maximum possible number of pairs of people dancing at the same time.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers (1<n,m<100000), indicating the number of gentlemen and ladies.

The second line contains integers a1,a2,a3…an (0 ≤\leq ai < 231-1, ai != ajfor all i != j ), indicating the height of each gentleman.

The third line contains integers b1,b2,b3…bm(0 ≤\leq bi < 231-1, bi != bjfor all i != j ), indicating the height of each lady.

The fourth line contains integers p1,p2,p3…pn(0 ≤\leq pi ≤\leq 1), indicating the preference of each gentleman. If , it means gentleman prefers to dance with a lady of smaller height. Otherwise it indicates he prefers to have a taller dancing partner.

The fifth line contains integers q1,q2,q3…qm(0 ≤\leq qi ≤\leq 1), indicating the preference of each lady. If , it means lady prefers to dance with a gentleman of smaller height. Otherwise it indicates she prefers to have a taller dancing partner.

It’s guaranteed that the sum of and of all test cases will not exceed 106 and ai != bj for all 1≤\leq i ≤\leq n, 1≤\leq j ≤\leq m.

Output

For each test case output one line containing one integer, indicating the answer.

Sample Input

1
3 3
1 2 5
3 4 6
1 1 0
0 0 1
Sample Output

2
Hint

In the sample test case, the 1st gentleman can dance with the 2nd lady, and the 2nd gentleman can dance with the 1st lady.

题目大意:
先输入一个整数t代表输入的测试组数,对于每组测试用例,先输入两个整数n,m,分别代表男士和女士的人数,下面四行,第一行输入的是n名男士的身高,第二行为m名女士的身高,第三行为男士期望他的舞伴(女)身高的标准,0代表他期望他的舞伴比他矮,1代表他期望他的舞伴比他高,第四行代表女士期望她的舞伴(男)身高的标准,同样,0代表希望舞伴比她矮,1代表希望舞伴比她高,问最多能有多少对舞者。

解题思路:
通过题意,我们能知道只有当男士要求为0,女士要求为1时,他们才能做舞伴,同理,男士要求为1,女士要求为0也一样,所以我们可以将男士要求为0的身高存在vector数组a0中,要求为1的存在vector数组a1中,女士同理存在b0,b1中,通过查找a0,b1中与a1,b0中符合题意的对数即可得到结果.

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
vector<int> a0,a1,b0,b1;
int a[100100],b[100100];
int main() 
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int t;scanf("%d",&t);while(t--) {a0.clear();a1.clear();b0.clear();b1.clear();int n,m;scanf("%d %d",&n,&m);rep(i,1,n) scanf("%d",&a[i]);rep(i,1,m) scanf("%d",&b[i]);int nape;int len1=0,len2=0,len3=0,len4=0;rep(i,1,n) {scanf("%d",&nape);if(nape==0) a0.push_back(a[i]),len1++;if(nape==1) a1.push_back(a[i]),len2++;}rep(i,1,m) {scanf("%d",&nape);if(nape==0) b0.push_back(b[i]),len3++;if(nape==1) b1.push_back(b[i]),len4++;}sort(a0.begin(),a0.end());sort(a1.begin(),a1.end());sort(b0.begin(),b0.end());sort(b1.begin(),b1.end());int ans=0;for(int i=0,j=0;i<len1&&j<len4;) {if(a0[i]>b1[j]) {ans++;i++;j++;}else i++;}for(int i=0,j=0;i<len2&&j<len3;) {if(b0[j]>a1[i]) {ans++;i++;j++;}else j++;}printf("%d\n",ans);}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/536296.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【二维差分】Monitor

Monitor 题目&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid6514 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 163840/163840 K (Java/Others) Total Submission(s): 600 Accepted Submission(s): 190 Problem Description Xiaoteng has a la…

【二分+二维前缀和】Largest Allowed Area

Largest Allowed Area 时间限制: 1 Sec 内存限制: 128 MB 提交: 146 解决: 54 [提交] [状态] [命题人:admin] 题目描述 A company is looking for land to build its headquarters. It has a lot of money and can buy as many land patches as it needs. Its goal, howev…

【数学】Floating-Point Hazard

Floating-Point Hazard 时间限制: 1 Sec 内存限制: 128 MB 提交: 106 解决: 42 [提交] [状态] [命题人:admin] 题目描述 Given the value of low, high you will have to find the value of the following expression: If you try to find the value of the above express…

【线段树】Segment Tree

Segment Tree 时间限制: 1 Sec 内存限制: 512 MB 提交: 107 解决: 23 [提交] [状态] [命题人:admin] 题目描述 Mcginn opens the code which he wrote 25 years ago. Clever Mcginn wants to know how many positive interger n satisfied that the maximum c can reach w…

扶桑号战列舰【RMQ+分治】

扶桑号战列舰 时间限制: 1 Sec 内存限制: 128 MB Special Judge 提交: 197 解决: 63 [提交] [状态] [命题人:admin] 题目描述 众所周知&#xff0c;一战过后&#xff0c;在世界列强建造超无畏级战列舰的竞争之中&#xff0c;旧日本海军根据“个舰优越主义”&#xff0c;建造了扶…

大凤号装甲空母【找规律+矩阵快速幂】

大凤号装甲空母 时间限制: 1 Sec 内存限制: 128 MB 提交: 108 解决: 15 [提交] [状态] [命题人:admin] 题目描述 大凤号航空母舰很喜欢算术。 它&#xff0c;是旧日本海军中最为先进的航空母舰。 它&#xff0c;是旧日本海军中最为短命的航空母舰。 同时&#xff0c;她还是最平…

Degree Sequence of Graph G【模拟】

Degree Sequence of Graph G 时间限制: 1 Sec 内存限制: 128 MB 提交: 362 解决: 92 [提交] [状态] [命题人:admin] 题目描述 Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep lov…

【动态规划】魔法石矿

【动态规划】魔法石矿 时间限制: 1 Sec 内存限制: 64 MB 提交: 116 解决: 27 [提交] [状态] [命题人:admin] 题目描述 为了找到回家的路&#xff0c;张琪曼施展魔法&#xff0c;从高维空间召唤出了一种叫作“读者”的生物&#xff0c;据说“读者”这种生物无所不能&#xff0c;…

简单类及成员实例【C#】

简单类及成员实例&#xff08;C#&#xff09; 题目描述 简单类及成员实例。定义了如下图所示类Student&#xff0c;根据下图和给出代码&#xff0c;补写缺失的代码。 using System; namespace sample{ class Student { public string studentid;//学号 p…

c#随机数的产生与输出【C#】

c#随机数的产生与输出 题目描述 编写一个实例方法Method01。该方法使用Random类随机产生n个3位数字&#xff08;如636&#xff09;的随机正整数&#xff0c;并把产生的随机数存入数组中并输出该数组int num Convert.ToInt32(Console.ReadLine()); using System; using System…

C# teacher类【C#】

C# teacher类 题目描述 定义一个教师类Teacher&#xff0c;具体要求如下&#xff1a; 1、私有字段工号no&#xff08;string&#xff09;、姓名name&#xff08;string&#xff09;、出生日期birthday&#xff08;DateTime&#xff09;、性别sex&#xff08;SexFlag&#xff0…

接口实例(C#,IShape)【C#】

接口实例&#xff08;C#,IShape&#xff09; 题目描述 接口实例。接口和类如下图所示&#xff0c;根据给出代码&#xff0c;补写缺失的代码&#xff0c;然后在Program类的静态Main方法中验证所实现的类。 using System; namespace Myinterface { public interface IShape…

1439: 2.4.5 Fractions to Decimals 分数化小数

1439: 2.4.5 Fractions to Decimals 分数化小数 时间限制: 1 Sec 内存限制: 64 MB提交: 194 解决: 13题目描述 写一个程序&#xff0c;输入一个形如N/D的分数(N是分子&#xff0c;D是分母)&#xff0c;输出它的小数形式。 如果小数有循环节的话&#xff0c;把循环节放在一对圆…

Problem B: 求各位数字之和

#include <stdio.h> #include <stdlib.h> int main() { int n,sum0,m; while(~scanf("%d",&n)) { while(n>0) { mn%10; nn/10; summ; } printf("%d\n",sum); sum0; } return 0; }

Problem C: 判断字符串是否为回文

#include <stdio.h> #include <stdlib.h> int main() { int i,j,n; char str[10]; gets(str); nstrlen(str); for(i0,jn-1;i<j;i,j--) { if(str[i]!str[j]) { printf("No\n"); break; } } if(i>j)printf("Yes\n"); return 0; }

Problem A: 童年生活二三事

斐波那契数列:F(n)F(n-1)F(n-2) #include <stdio.h> #include <stdlib.h> int f(int n) {int b;if(n1)b1;if(n2)b2;if(n>2)bf(n-1)f(n-2);return b; }int main() {int a,n;while(~scanf("%d",&n)&&n!0){af(n);printf("%d\n",a…

Problem C: 01字串

#include <stdio.h> #include <stdlib.h>int main() {int i,j,n0,m0;char a[129][8];for(i0;i<128;i){for(j0;j<7;j){a[i][j]n%2;nn/2;}m;nm;}for(i0;i<128;i){for(j6;j>0;j--)printf("%d",a[i][j]);printf("\n");}return 0; }

汉诺塔III

#include <stdio.h> #include <stdlib.h> int main() {int fx(int );int n,m;while(~scanf("%d",&n)){mfx(n);printf("%d\n",m);}return 0; } int fx(int n) {int m;if(n1)m2;if(n>1)m3*fx(n-1)2;return m; }

骨牌铺方格

骨牌铺方格 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 46495 Accepted Submission(s): 22470 Problem Description在2n的一个长方形方格中,用一个1 2的骨牌铺满方格,输入n ,输出铺放方案的总数.例如n3时…

递归思想完成n皇后问题

已经很长时间不敲代码了&#xff0c;感觉自己越来与颓废&#xff0c;所以现在又想做回一名苦逼的程序员&#xff0c;开启自己的代码之路。 我是根据视频敲的&#xff0c;没有题目&#xff0c;先看个四皇后问题吧。 所谓4皇后问题就是求解如何在44的棋盘上无冲突的摆放4个皇后棋…