【Java/补题/牛客/ACM赛制】第十九届浙大城市学院程序设计竞赛(同步赛)

题目链接

第十九届浙大城市学院程序设计竞赛(同步赛)

知识一览

01-数论(F题)
02-动态规划(I题)
03-子串倒置/字典序/前缀

题目列表

快输

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        String tmp;

        public FastReader() {
            br=new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while(st==null||!st.hasMoreElements()) {
                try {
                    st=new StringTokenizer(br.readLine());
                }catch(IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong(){return Long.parseLong(next());}

        String nextLine() {
            String str="";
            try {
                str=br.readLine();
            }catch(IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        boolean hasNext(){
            if(st!=null&&st.hasMoreTokens())return true;
            try {
                tmp=br.readLine();
                st=new StringTokenizer(tmp);
            }catch(IOException e) {
                return false;
            }
            return true;
        }
    }

    static PrintWriter out=new PrintWriter(
            new BufferedWriter(new OutputStreamWriter(System.out)));
    static FastReader sc=new FastReader();

F Sum of Numerators(分子之和)

F题

	public static void main(String[] args) {
        int t=sc.nextInt();
        while(t-->0) {
            long n=sc.nextLong(),k=sc.nextLong();
            long sum=n*(n+1)/2;
            while(k>0){
                k--;
                n/=2;
                if(n==0)break;
                sum-=n*(n+1)/2;
            }

            out.println(sum);
            out.flush();
        }
    }

I Array Division(数组划分)

题意:对两个数组进行相同的划分,划分得到的每一个子数组中,a数组中的元素之和大于等于b数组中的元素之和。若可以进行这样的划分,则输出最大组数;否则输出-1。

	public static void main(String[] args) {
        int t=sc.nextInt();
        while(t-->0) {
            int n=sc.nextInt();
            //a & b 数组前缀和
            long a[]=new long[n+1],b[]=new long[n+1];
            for(int i=1;i<=n;i++){
                a[i]=sc.nextLong();a[i]+=a[i-1];
            }
            for(int i=1;i<=n;i++){
                b[i]=sc.nextLong();b[i]+=b[i-1];
            }
            if(a[n]<b[n]){
                out.println(-1);out.flush();
                continue;
            }
            long dp[]=new long[n+1];
            for(int i=1;i<=n;i++){
            //前i个数字还没有进行划分,但可以被分为一组(a[i]>=b[i])
                if(dp[i]==0&&a[i]>=b[i])
                    dp[i]=1;
                for (int j=i-1;j>=0;j--){
                //若dp[j]=0,则前j个数字不能进行划分
                    if((a[i]-a[j])>=(b[i]-b[j])&&dp[j]!=0){
                        dp[i]=Math.max(dp[i],dp[j]+1);
                    }
                }
            }
            out.println(dp[n]);
            out.flush();
        }
    }

J - Substring Inversion (Easy Version)(子字符串反转(简易版))

找符合以下条件的元组(a,b,c,d) 个数
①1≤a≤b≤n
②1≤c≤d≤n
③a < c
④s[a:b] is lexicographically greater(字典序靠前) than s[c:d]

	static int mod=(int)1e9+7;
    static int n;
    public static void main(String[] args) {
        int T=sc.nextInt();
        //int T=1;
        while(T-->0){
            solve();
        }
    }
    private static void solve(){
        n=sc.nextInt();
        char s[]=(sc.next()).toCharArray();
        long ans=0;
        for (int i=0;i<n;i++) {
            for (int j=i+1;j<n;j++) {
                int a=i,b=j;
                while (b<n&&s[a]==s[b]) {
                    ans=(ans+n-a-1)%mod;
                    a++;b++;
                }
                if(b>=n){
                    a--;b--;
                }
                if (s[a]>s[b])  {
                    ans+=(n-a)*(n-b)%mod;
                    ans%=mod;
                }
            }
        }
        out.println(ans);
        out.flush();
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值