2019牛客ACM暑期多校第一场

太菜了 就过了一道题。
A-Equivalent Prefixes

题目描述

 

Two arrays u and v each with m distinct elements are called equivalent if and only if RMQ(u,l,r)=RMQ(v,l,r)RMQ(u,l,r)=RMQ(v,l,r) for all 1≤l≤r≤m1≤l≤r≤m
 where RMQ(w,l,r)RMQ(w,l,r) denotes the index of the minimum element among wl,wl+1,…,wrwl,wl+1,…,wr.
 Since the array contains distinct elements, the definition of minimum is unambiguous.
 
 Bobo has two arrays a and b each with n distinct elements. Find the maximum number p≤np≤n where {a1,a2,…,ap}{a1,a2,…,ap} and {b1,b2,…,bp}{b1,b2,…,bp} are equivalent.

输入描述:
The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains an integer n.
The second line contains n integers a1,a2,…,ana1,a2,…,an.
The third line contains n integers b1,b2,…,bnb1,b2,…,bn.

* 1≤n≤1051≤n≤105
* 1≤ai,bi≤n1≤ai,bi≤n
* {a1,a2,…,an}{a1,a2,…,an} are distinct.
* {b1,b2,…,bn}{b1,b2,…,bn} are distinct.
* The sum of n does not exceed 5×1055×105.
输出描述:
For each test case, print an integer which denotes the result.


示例1

 

输入
复制

2
1 2
2 1
3
2 1 3
3 1 2
5
3 1 5 2 4
5 2 4 3 1

 

输出
复制

1
3
4

一开始读错题了 wa了好多次 发现了之后本以为n^2过不了就没试 。看了别人的代码才知道  

承认下面的代码有点问题。但能过

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],b[N];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        for(int i=0; i<n; i++)
            scanf("%d",&b[i]);
        int cnt=n-1;
        for(int i=0; i<=cnt; i++)
        {
            for(int j=i+1; j<=cnt; j++)
            {
                int f=0;
                if(a[i]>a[j])
                    f++;
                if(b[i]>b[j])
                    f++;
                if(f==1)
                {
                    cnt=j-1;
                    break;
                }
                if(f==2)
                    break;
            }
        }
        cout<<cnt+1<<'\n';
    }
    return 0;
}

 用单调栈做的人挺多的

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
const int INF=1e9;
ll a[maxn],b[maxn];
stack<ll >s1,s2;
int main()
{
    ll n;
    while(~scanf("%lld",&n))
    {
        while(!s1.empty())
            s1.pop();
        while(!s2.empty())
            s2.pop();
        for(int i=1; i<=n; i++)
            scanf("%lld",&a[i]);
        for(int i=1; i<=n; i++)
            scanf("%lld",&b[i]);
        s1.push(a[1]);
        s2.push(b[1]);
        int i;
        for(i=2; i<=n; i++)
        {
            while(!s1.empty()&&a[i]<s1.top())//递减的单调栈
                s1.pop();
            s1.push(a[i]);
            while(!s2.empty()&&b[i]<s2.top())
                s2.pop();
            s2.push(b[i]);
            if(s1.size()!=s2.size())
                break;
        }
        printf("%d\n",i-1);
    }
    return 0;
}

 

F-Random Point in Triangle

题目描述

 


Bobo has a triangle ABC with A(x1,y1),B(x2,y2)A(x1,y1),B(x2,y2) and C(x3,y3)C(x3,y3). Picking a point P uniformly in triangle ABC, he wants to know the expectation value E=max{SPAB,SPBC,SPCA}E=max{SPAB,SPBC,SPCA} where SXYZSXYZ denotes the area of triangle XYZ.
 
 Print the value of 36×E36×E. It can be proved that it is always an integer.
输入描述:
The input consists of several test cases and is terminated by end-of-file.

Each test case contains six integers x1,y1,x2,y2,x3,y3x1,y1,x2,y2,x3,y3.

* |x1|,|y1|,|x2|,|y2|,|x3|,|y3|≤108|x1|,|y1|,|x2|,|y2|,|x3|,|y3|≤108
* There are at most 105105 test cases.
输出描述:
For each test case, print an integer which denotes the result.


示例1

 

输入
复制

0 0 1 1 2 2
0 0 0 0 1 1
0 0 0 0 0 0

 

输出
复制

0
0
0

首先普及一下三角形面积公式
1.S=(1/2)*a*b*sinC
2.S=(1/2)*|(x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2)|    ///来源于叉乘
3.S=sqrt(p*(p-a)*(p-b)*(p-c))    p=(1/2)(a+b+c)     ///海伦公式
4.略

大佬用二重积分推出来的比值 选正三角形为特例
期望E=(11/2)*S

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long x1,x2,x3,y1,y2,y3;
    while(scanf("%lld%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF)
    {
        long long s=x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2;
        cout<<abs(s*11)<<'\n';
    }
    return 0;
}

 

J-Fraction Comparision

题目描述

 


Bobo has two fractions xaxa and ybyb. He wants to compare them. Find the result.
输入描述:
The input consists of several test cases and is terminated by end-of-file.

Each test case contains four integers x, a, y, b.

* 0≤x,y≤10180≤x,y≤1018
* 1≤a,b≤1091≤a,b≤109
* There are at most 105105 test cases.
输出描述:
For each test case, print `=` if xa=ybxa=yb. Print `<` if xa<ybxa<yb. Print `>` otherwise.


示例1

 

输入
复制

1 2 1 1
1 1 1 2
1 1 1 1

 

输出
复制

<
>
=

唯一过了的题qaq
感悟:python java真是好东西
python:

while True:
    try:
        x,a,y,b=map(int,input().split())
        if x*b>y*a:
            print(">")
        elif x*b<y*a:
            print("<")
        else:
            print("=")
    except:
        break


Java(偷来的一块代码):

import java.io.*;
import java.math.*;
import java.util.*;
import java.math.*;
public class Main
{
    public static void main( String []args)
    {
        Scanner cin = new Scanner(System.in);
        BigInteger a,b,c,d,e,f;
        while(cin.hasNext())
        {
            a = cin.nextBigInteger();
            b = cin.nextBigInteger();
            c = cin.nextBigInteger();
            d = cin.nextBigInteger();
            e = b.multiply(c);
            f = a.multiply(d);
            if(e.compareTo(f) == 0)
                System.out.println("=");
            else if(e.compareTo(f) > 0)
                System.out.println('<');
            else
                System.out.println('>');
        }
    }
}


E-ABBA

题目描述

 

Bobo has a string of length 2(n + m) which consists of characters `A` and `B`. The string also has a fascinating property: it can be decomposed into (n + m) subsequences of length 2, and among the (n + m) subsequences n of them are `AB`  while other m of them are `BA`.
 
 Given n and m, find the number of possible strings modulo (109+7)(109+7).
输入描述:
The input consists of several test cases and is terminated by end-of-file.

Each test case contains two integers n and m.

* 0≤n,m≤1030≤n,m≤103
* There are at most 2019 test cases, and at most 20 of them has max{n,m}>50max{n,m}>50.
输出描述:
For each test case, print an integer which denotes the result.


示例1

 

输入
复制

1 2
1000 1000
0 0

 

输出
复制

13
436240410
1

dp
记得开long long

dp[i][j]是添加到i个A j个B时的方案数。

i<=n时  A可以随意添。i>n时 前面有多余的B时可以添 即i<=n+j

j<=m时 B可以随意添。j>m时 前面有多余的A时可以添 即j<m+i

 

#include <bits/stdc++.h>
using namespace std;

const int N=2e3+5;
const int MOD=1e9+7;
long long dp[N][N];

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=0;i<=n+m;i++)
        {
            for(int j=0;j<=n+m;j++)
                dp[i][j]=0;
        }
        dp[0][0]=1;
        for(int i=0;i<=n+m;i++)
        {
            for(int j=0;j<=n+m;j++)
            {
                if(i<n+j)
                    dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
                if(j<m+i)
                    dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MOD;
            }
        }
        cout<<dp[n+m][n+m]<<'\n';
    }
    return 0;
}

暂时补了这么多。抽空继续。
 

全部评论

相关推荐

刚刷到字节跳动官方发的消息,确实被这波阵仗吓了一跳。在大家还在纠结今年行情是不是又“寒冬”的时候,字节直接甩出了史上规模最大的转正实习计划——ByteIntern。咱们直接看几个最硬的数,别被花里胡哨的宣传词绕晕了。首先是“量大”。全球招7000多人是什么概念?这几乎是把很多中型互联网公司的总人数都给招进来了。最关键的是,这次的资源分配非常精准:研发岗给了4800多个Offer,占比直接超过六成。说白了,字节今年还是要死磕技术,尤其是产品和AI领域,这对于咱们写代码的同学来说,绝对是今年最厚的一块肥肉。其次是大家最关心的“转正率”。官方直接白纸黑字写了:整体转正率超过50%。这意味着只要你进去了,不划水、正常干,每两个人里就有一个能直接拿校招Offer。对于2027届(2026年9月到2027年8月毕业)的同学来说,这不仅是实习,这简直就是通往大厂的快捷通道。不过,我也得泼盆冷水。坑位多,不代表门槛低。字节的实习面试出了名的爱考算法和工程实操,尤其是今年重点倾斜AI方向,如果你简历里有和AI相关的项目,优势还是有的。而且,转正率50%也意味着剩下那50%的人是陪跑的,进去之后的考核压力肯定不小。一句话总结:&nbsp;27届的兄弟们,别犹豫了。今年字节这是铁了心要抢提前批的人才,现在投递就是占坑。与其等到明年秋招去千军万马挤独木桥,不如现在进去先占个工位,把转正名额攥在手里。
喵_coding:别逗了 50%转正率 仔细想想 就是转正与不转正
字节7000实习来了,你...
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
10656次浏览 93人参与
# 你的实习产出是真实的还是包装的? #
1901次浏览 42人参与
# MiniMax求职进展汇总 #
24047次浏览 309人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7582次浏览 43人参与
# 简历第一个项目做什么 #
31706次浏览 336人参与
# 重来一次,我还会选择这个专业吗 #
433478次浏览 3926人参与
# 米连集团26产品管培生项目 #
5966次浏览 216人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
187146次浏览 1122人参与
# 牛客AI文生图 #
21439次浏览 238人参与
# 不考虑薪资和职业,你最想做什么工作呢? #
152386次浏览 888人参与
# 研究所笔面经互助 #
118933次浏览 577人参与
# 简历中的项目经历要怎么写? #
310250次浏览 4212人参与
# AI时代,哪些岗位最容易被淘汰 #
63652次浏览 823人参与
# 面试紧张时你会有什么表现? #
30506次浏览 188人参与
# 你今年的平均薪资是多少? #
213084次浏览 1039人参与
# 你怎么看待AI面试 #
180047次浏览 1255人参与
# 高学历就一定能找到好工作吗? #
64326次浏览 620人参与
# 你最满意的offer薪资是哪家公司? #
76494次浏览 374人参与
# 我的求职精神状态 #
448052次浏览 3129人参与
# 正在春招的你,也参与了去年秋招吗? #
363400次浏览 2638人参与
# 腾讯音乐求职进展汇总 #
160643次浏览 1112人参与
# 校招笔试 #
470936次浏览 2964人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务