首页 > 其他分享 >AtCoder 333 A-D

AtCoder 333 A-D

时间:2023-12-19 21:55:46浏览次数:33  
标签:AtCoder charAt int System 333 static println out

A Three Threes (打表

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        if (n == 1) System.out.println(1);
        if (n == 2) System.out.println(22);
        if (n == 3) System.out.println(333);
        if (n == 4) System.out.println(4444);
        if (n == 5) System.out.println(55555);
        if (n == 6) System.out.println(666666);
        if (n == 7) System.out.println(7777777);
        if (n == 8) System.out.println(88888888);
        if (n == 9) System.out.println(999999999);
    }
}

B Pentagon (判断是否是同类型的边

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s12 = sc.next();
        String t12 = sc.next();

        boolean fs12 = false; // 相邻是true
        boolean ft12 = false; // 相邻是true

        if (s12.charAt(1) == s12.charAt(0) + 1 || s12.charAt(1) == 'E' && s12.charAt(0) == 'A' || s12.charAt(1) == 'A' && s12.charAt(0) == 'E' || s12.charAt(0) == s12.charAt(1) + 1) fs12 = true;
        if (t12.charAt(1) == t12.charAt(0) + 1 || t12.charAt(1) == 'E' && t12.charAt(0) == 'A' || t12.charAt(1) == 'A' && t12.charAt(0) == 'E' || t12.charAt(0) == t12.charAt(1) + 1) ft12 = true;

        if (fs12 == ft12) System.out.println("Yes");
        else System.out.println("No");
    }
}

C Repunit Trio (三重循环暴力枚举

import java.util.*;

class Main {
    static long[] arr = new long[1000010];
    static long[] base = {1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111, 11111111111L, 111111111111L};
    static long[] ans = new long[1000010];
    static int idx = 0;
    static int idxa = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        for (int i = 0; i < base.length; i ++ )
            for (int j = 0; j < base.length; j++)
                for (int k = 0; k < base.length; k++)
                    arr[idx++] = base[i] + base[j] + base[k];

        Arrays.sort(arr, 0, idx);
//        for (int i = 0; i < 10; i ++ ) System.out.print(arr[i] + " ");
        for (int i = 0; i < idx; i ++ ) {
            if (i == 0) ans[idxa ++ ] = arr[i];
            else if (arr[i] != arr[i - 1]) ans[idxa ++ ] = arr[i];
        }

//        System.out.println(idxa);
//        for (int i = 0; i < 20; i ++ ) System.out.print(ans[i] + " ");

        System.out.println(ans[n - 1]);
    }
}

D Erase Leaves (找出节点1的n - 1个子树的最小节点和

import java.util.*;

class Main {
    static int[] h, e, ne, arr;
    static int idx, idxarr;
    static int n;
    static int ans = 0;

    private static void init() {
        h = new int[2 * n + 100]; e = new int[2 * n + 100]; ne = new int[2 * n + 100];
        arr = new int[2 * n + 100];
        Arrays.fill(h, -1);
    }
    private static void add(int a, int b) {
        e[idx] = b; ne[idx] = h[a]; h[a] = idx ++ ;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 找ver1的其中n - 1棵树的最小总和
        n = sc.nextInt();
        init();
        for (int i = 1; i <= n - 1; i ++ ) {
            int u = sc.nextInt(), v = sc.nextInt();
            add(u, v);
            add(v, u);
        }

        int d1 = 0;
        for (int i = h[1]; i != -1; i = ne[i] ) {
            int j = e[i];
            arr[idxarr ++ ] = dfs(j, 1);
            d1 ++ ;
        }

        Arrays.sort(arr, 0, idxarr);
//        System.out.println("debug -> d1 : " + d1);
        for (int i = 0; i < d1 - 1; i ++ ) ans += arr[i];
        System.out.println(ans + 1);
    }

    public static int dfs(int u, int fa) {
        int ret = 1;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int j = e[i];
            if (j == fa) continue;
            ret += dfs(j, u);
        }

        return ret;
    }
}

标签:AtCoder,charAt,int,System,333,static,println,out
From: https://www.cnblogs.com/llihaotian666/p/17914891.html

相关文章

  • AtCoder Beginner Contest 333
    B-Pentagon难度:⭐题目大意给定一个正五边形,其顶点为ABCDE;给定端点a,b,c,d;问a,b之间的距离和c,d之间的距离是否相等;解题思路两个端点之间的距离就看两个端点之间隔了几条边就行;并且因为是五边形,隔x条边和隔5-x条边是等价的;神秘代码#include<bits......
  • Atcoder ABC 333 题解(A - F)
    ABC不讲D待更E待更F设$f(i,j)$为有$i$个人时,第$j$个人活到最后的概率,显然:\[f(i,j)=\begin{cases}1,&i=1,j=1\\\frac{1}{2}f(i,i),&i\neq1,j=1\\\frac{1}{2}f(i,j-1)+\frac{1}{2}f(i-1,j-1),&i\neq1,2\lej......
  • AtCoder Beginner Contest 324
    C-ErrorCorrection大意是:给定一个字符串a,以及一组字符串,如果字符串与a满足以下之一即可我写的有点麻烦。。#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ intn; cin>>n; strings; cin>>s; vector<int>ans; for(inti=1;i<=n;i++){ stringt; ci......
  • CF333D 另一种做法
    前言duel的时候做的题,做出来的时候感觉很神,看了题解做法感觉自己是个傻逼。本做法时间复杂度是\(O(n^{\tfrac{5}{2}})\),可以作为补充了解。题解一个矩阵四个角的最大值有点烦,我们把它们排序,从小到大依次插入,则问题变为:在\(n\timesm\)的平面中,每次插入一个点,求在什么时候......
  • 【题解】AtCoder agc065_a Shuffle and mod K
    传送门:https://atcoder.jp/contests/agc065/tasks/agc065_a 为了方便理解,我们把要求的东西乘一个$-1$,再把答案序列倒过来;也就是说,我们现在要求$min_{A'}^{A'为A的排列}(\sum_{i=1}^{N-1}((A_{i+1}-A_{i})$$mod$$K))$比较显然的是,如果我们确定了答案序列的第一个数是多......
  • Toyota Programming Contest 2023#8(AtCoder Beginner Contest 333)
    ToyotaProgrammingContest2023#8(AtCoderBeginnerContest333)A-ThreeThrees代码:#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=1e6+10;typedefpair<ll,ll>pii;#definefifirst#definesesecondvoid......
  • 题解 ABC333F【Bomb Game 2】
    来个可能有点麻烦但不用动脑子的暴力做法。直接设\(f_{i,j}\)表示有\(i\)个人时,第\(j\)个人幸存的概率。显然有\(f_{1,1}=1\)。对于\(i>1\),分类讨论容易得到:\[f_{i,j}=\begin{cases}\frac{f_{i,n}}{2},&j=1\\\frac{f_{i-1,j-1}+f_{i,j-1}}{2},&1<j\lei\\\e......
  • AtCoder Beginner Contest 325
    C-Sensors但看数据发现是经典油田问题,直接dfs#include<bits/stdc++.h>usingnamespacestd;intn,m;intdx[8]={-1,-1,-1,0,1,1,1,0};intdy[8]={-1,0,1,1,1,0,-1,-1};intvis[1005][1005];charmp[1005][1005];voiddfs(intx,inty){ vis[x][y]=......
  • AtCoder Beginner Contest 332
    C-T-shirts题意是:给定一个string,字符代表每天有不同的事,做不同的事会穿不同的衣服,问你最少需要准备多少T恤。思路:贪心,能不用T恤就不要T恤#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ intn,k; cin>>n>>k; strings; cin>>s; intans=0; intcnt=k; i......
  • AT_abc333_e [ABC333E] Takahashi Quest 题解
    AT_abc333_e[ABC333E]TakahashiQuest题解思路解析可以发现一瓶药水无论什么时候拿被使用掉的时间都是不会变的,所以如果我们想让一瓶药水再背包里待得时间尽可能的短就要让它尽可能的被晚拿起来,于是我们就可以想到使用栈存下每一瓶同类的药水分别出现的时间,此时每遇到一只怪......