【模擬】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.pswp.cn/news/536296.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/536296.shtml
英文地址,請注明出處:http://en.pswp.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…

【數學】MORE XOR

Given a sequence of nnn numbers a1,a2,?&ThinSpace;,ana_1, a_2,\cdots, a_na1?,a2?,?,an? and three functions. Define a function f(l,r)f(l,r)f(l,r) which returns ⊕a[x](l≤x≤r)\oplus a[x] (l \le x \le r)⊕a[x](l≤x≤r). The \oplus⊕ represents excl…

【數學】Element Swapping

Element Swapping Time Limit: 1 Second Memory Limit: 65536 KB DreamGrid has an integer sequence a1,a2,a3,…,ana_1,a_2,a_3,\dots,a_na1?,a2?,a3?,…,an? and he likes it very much. Unfortunately, his naughty roommate BaoBao swapped two elements aia_iai? an…

【二分+二維前綴和】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…

【manacher】Strings in the Pocket

Strings in the Pocket Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found two strings ss1s2…snss_1s_2\dots s_nss1?s2?…sn? and tt1t2…tntt_1t_2\dots t_ntt1?t2?…tn? in his left pocket, where sis_isi? indicates the iii-th character in…

【并查集+dp】Team

Team 時間限制: 1 Sec 內存限制: 128 MB 提交: 124 解決: 10 [提交] [狀態] [命題人:admin] 題目描述 ACM-ICPC is a interesting game. A team takes part in this game must consist of exactly (no more and no less) three players. Every year, many new members wil…

【線段樹】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 satis?ed that the maximum c can reach w…

UVA1025——A Spy in the Metro【dp】

題目鏈接&#xff1a;https://cn.vjudge.net/problem/UVA-1025 題目大意&#xff1a;Mario從第1站出發&#xff0c;目的是在時刻T會見車站 nnn 的一個間諜。由于在車站等待容易被抓&#xff0c;所以應盡量躲在開動的火車上&#xff0c;即在車站等待的時間最短&#xff0c;且Ma…

HDU1284——錢幣兌換問題【dp】

錢幣兌換問題 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14528 Accepted Submission(s): 8784 Problem Description 在一個國家僅有1分&#xff0c;2分&#xff0c;3分硬幣&#xff0c;將錢N兌換成硬…

HDU6092——Rikka with Subset 【dp】

題目網址&#xff1a; https://vjudge.net/problem/HDU-6092 As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has nn positive A1?AnA1?An and their sum is mm…

洛谷P1725琪露諾【單調隊列+dp】

題目描述 在幻想鄉&#xff0c;琪露諾是以笨蛋聞名的冰之妖精。 某一天&#xff0c;琪露諾又在玩速凍青蛙&#xff0c;就是用冰把青蛙瞬間凍起來。但是這只青蛙比以往的要聰明許多&#xff0c;在琪露諾來之前就已經跑到了河的對岸。于是琪露諾決定到河岸去追青蛙。 小河可以看…

扶桑號戰列艦【RMQ+分治】

扶桑號戰列艦 時間限制: 1 Sec 內存限制: 128 MB Special Judge 提交: 197 解決: 63 [提交] [狀態] [命題人:admin] 題目描述 眾所周知&#xff0c;一戰過后&#xff0c;在世界列強建造超無畏級戰列艦的競爭之中&#xff0c;舊日本海軍根據“個艦優越主義”&#xff0c;建造了扶…

大鳳號裝甲空母【找規律+矩陣快速冪】

大鳳號裝甲空母 時間限制: 1 Sec 內存限制: 128 MB 提交: 108 解決: 15 [提交] [狀態] [命題人:admin] 題目描述 大鳳號航空母艦很喜歡算術。 它&#xff0c;是舊日本海軍中最為先進的航空母艦。 它&#xff0c;是舊日本海軍中最為短命的航空母艦。 同時&#xff0c;她還是最平…

codevs5429 多重背包【多重背包+單調隊列】

5429 多重背包 時間限制: 1 s 空間限制: 256000 KB 題目等級 : 鉆石 Diamond 題目描述 Description 你有一個容量為M的背包&#xff0c;和N種物品。 每種物品都有三個屬性&#xff0c;vi&#xff0c;wi&#xff0c;與ci&#xff0c;分別表示這種物品的體積、價值和件數。 你的…

generator 1【矩陣快速冪】

題目描述 You are given four positive integers x0,x1,a,bx_0, x_1, a, bx0?,x1?,a,b. And you know xia?xi?1b?xi?2x_i a \cdot x_{i-1} b \cdot x_{i-2}xi?a?xi?1?b?xi?2? for all i≥2i \ge 2i≥2. Given two positive integers n, and MOD, please calcul…

Give Candies【快速冪+歐拉】

Give Candies 時間限制: 1 Sec 內存限制: 128 MB 提交: 243 解決: 92 [提交] [狀態] [命題人:admin] 題目描述 There are N children in kindergarten. Miss Li bought them N candies。To make the process more interesting, Miss Li comes up with the rule: All the childr…

Save the Room【找規律】

Save the Room 時間限制: 1 Sec 內存限制: 128 MB 提交: 149 解決: 90 [提交] [狀態] [命題人:admin] 題目描述 Bob is a sorcerer. He lives in a cuboid room which has a length of A, a width of B and a height of C, so we represent it as ABC. One day, he finds that …

Participate in E-sports【Java大數+二分】

Participate in E-sports 時間限制: 2 Sec 內存限制: 128 MB 提交: 194 解決: 53 [提交] [狀態] [命題人:admin] 題目描述 Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don’t know which one to choose, so they use a way to…

Poor God Water【矩陣快速冪】

Poor God Water 時間限制: 1 Sec 內存限制: 128 MB 提交: 102 解決: 50 [提交] [狀態] [命題人:admin] 題目描述 God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonou…