ZOJ-4090 Thanks, TuSimple!(感谢你,图森未来公司)(贪心+赞助商广告)

ZOJ Problem Set - 4090

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.

于2015年建立,位于San Diego的图森公司是全球自动化卡车行业的领导者,在亚利桑那州的图森开展无人驾驶卡车的业务。图森公司现在正在筹划一种面向商业的四级(SAE标准)完全自动驾驶汽车的方案,提供给物流公司使用。图森卡车是第一个也是唯一一个实现仓库到仓库的无人驾驶技术的公司,每天都通过这种技术为它的顾客服务。这个公司被一种理念驱使去提高安全性,减少运输消耗,以及降低碳排放。

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.

现如今,卡车工业正面临着缺失50000名司机(这个数字在2024会提升到175000)的窘境,并在司机人均年龄超过49岁的情况下有着接近100%的人事变更比率?根据一项PwC调查,自动驾驶的汽车技术将会每年在传统又平庸的运货大卡车那里减少28%的操作费用,图森公司志在以减少开支,降低碳排放的情况下给7400亿美刀的卡车工业转型。并通过操作者解决一些当前面临的挑战性的问题。

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(由于题面关键数据范围无法复制,所以这里不做赘译,详情请见http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4090

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  (), indicating the number of gentlemen and ladies.

The second line contains  integers  (,  for all ), indicating the height of each gentleman.

The third line contains  integers  (,  for all ), indicating the height of each lady.

The fourth line contains  integers  (), 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  (), 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  and  for all .

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.

看到这个题,全体数据分为两组

  1.  男士的身高与偏好
  2. 女士的身高与偏好

目标既然是求最大对数,自然是要找到最合适的对子,也就是说,身高差绝对值较小的方案比较“不浪费身高”。那么怎么去实现这些呢?首先便是对两组数据(结构体)分别排序(排序方案现在未定),从而找到身高大小之间的关系。

上面的数据分组看起来不那么完美——两种偏好夹在一起使得各种适配麻烦了许多。所以我们必须要选择一组数据根据偏好进行拆分,这里选择拆分女士数据,然后让男士适配女士(很真实...)。

那么数据就变成了

  1. 男士的身高与偏好
  2. 喜欢高男士的女士的身高 
  3. 喜欢矮男士的女士的身高

 那么可以设计排序方案了,总的方针是:用高的喜欢矮的男士去适配高的喜欢高的女士,用矮的喜欢高的男士去适配高的喜欢矮的女士。

总的思路:

  1. 在输入中或输入后根据喜好,把女士(或男士)的数据分组。
  2. 根据设定的方案进行排序
  3. 根据设定的方案进行遍历查找

具体细节见代码

#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf("%lld",&a)
#define din(a) scanf("%d",&a)
#define printlnlld(a) printf("%lld\n",a)
#define printlnd(a) printf("%d\n",a)
#define printlld(a) printf("%lld",a)
#define printd(a) printf("%d",a)
#define reset(a,b) memset(a,b,sizeof(a))
const int INF=0x3f3f3f3f;
using namespace std;
const double PI=acos(-1);
typedef long long ll;
typedef long double ld;
///Schlacht von Stalingrad
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
struct info
{
    ll hei,pre;
}man[750000],lady[750000];
vector<ll>a,b;
bool cmp(info a,info b)
{
    return a.hei<b.hei;
}
bool cmp2(ll a,ll b)
{
    return a>b;
}
int DETERMINATION()
{
    ll t;
    lldin(t);
    while(t--)
    {
        a.clear();
        b.clear();
        ll n,m;
        lldin(n),lldin(m);
        for(int i=1;i<=n;i++)
            lldin(man[i].hei);//结构体输入
        for(int i=1;i<=m;i++)
            lldin(lady[i].hei);
        for(int i=1;i<=n;i++)
            lldin(man[i].pre);
        for(int i=1;i<=m;i++)
            lldin(lady[i].pre);
        sort(man+1,man+1+n,cmp);//将男士依据身高从矮到高排序
        for(int i=1;i<=m;i++)
        {
            if(lady[i].pre==1)
                a.push_back(lady[i].hei);//根据女士喜好分组
            else
                b.push_back(lady[i].hei);
        }
        sort(a.begin(),a.end());//喜欢矮的,就从矮到高排序
        sort(b.begin(),b.end(),cmp2);//喜欢高的,就从高到矮排序
//cout<<"!"<<endl;
        ll pointer=0,pointer2=0;//定义两个指针
        ll ans=0;
        for(int i=n;i>=1;i--)
        {
            if(man[i].pre==1)//如果这个男人喜欢矮的
            {
                if(pointer<=b.size())
                {
                    if(b[pointer]>man[i].hei)//满足条件
                    {
                        pointer++;
                        ans++;
                    }
                }
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(man[i].pre==0)//如果这个男人喜欢高的
            {
                if(pointer2<=a.size())
                {
                    if(a[pointer2]<man[i].hei)
                    {
                        pointer2++;
                        ans++;
                    }
                }
            }
        }
        printlnlld(ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43874261/article/details/89578697