2019 춘계 기술 초빙 부분 프로그래밍 문제에 대한 확신

6081 단어
하위 문자열 모호 일치
package testShenXinFu;

import java.util.Scanner;

public class Main1 {

    public static void main(String[] args) {

        Scanner cin = new Scanner(System.in);
        String str = cin.next();
        String sub = cin.next();
        boolean[][] dp = new boolean[sub.length() + 1][str.length() + 1];
        dp[0][0] = true;

        //dp[i][j]    sub i     str j        
        for (int i = 1; i <= sub.length(); i++) {

            int count = 0;
            if (sub.charAt(i-1) == '?')
                count = 3;
            for (int j = i; j <= str.length(); j++) {
                if (count > 0) {
                    if (str.charAt(j - 1) != '\0' && (dp[i - 1][j - 1] || dp[i][j - 1])) {
                        dp[i][j] = true;
                        count--;
                    } else if (str.charAt(j - 1) == '\0') {
                        dp[i][j] = false;
                        count = 0;
                    }
                } else {
                    if (str.charAt(j - 1) == sub.charAt(i - 1))
                        dp[i][j] = dp[i - 1][j - 1];
                    else
                        dp[i][j] = false;
                }
            }
        }
        for (int i=0;i<=sub.length();i++){
            for(int j=0;j<=str.length();j++)
                System.out.print(dp[i][j]+" ");
            System.out.println();
        }
        int n=sub.length();
        for(int i=str.length();i>=0;i--){
            if(dp[n][i])
            {
                System.out.println(i);
                break;
            }
        }
        System.out.println(-1);
    }
/**
 * abcdefg
 * a?c
 *
 *
 */
}


집결
package testShenXinFu;

import java.util.Scanner;

public class Main3 {

    public static int[] record;

    public static void main(String[] args) {

        Scanner cin = new Scanner(System.in);
        int K = cin.nextInt();
        int N = cin.nextInt();
        int[] nums = new int[K];
        for (int i = 0; i < K; i++)
            nums[i] = cin.nextInt();
        record = new int[N];
        recursive(0, N, nums,K);
    }

    public static void recursive(int idx, int target, int[] nums, int K) {

        if (idx == K) {
            if (target == 0) {
                for (int i = 0; i < K; i++)
                    System.out.print(record[i]);
                System.out.println();
            }
            return;
        }
        for (int j = 0; j <= nums[idx] && j<=target; j++){
                record[idx]=j;
                recursive(idx+1,target-j,nums,K);
        }
    }
}


직사각형의 배치
package testShenXinFu;

import java.util.Arrays;
import java.util.Scanner;

public class Main2 {

    public static int n;

    public static void main(String[] args) {

        Scanner cin = new Scanner(System.in);
        int N=cin.nextInt();
        int[] arr=new int[3];
        for(int i=0;i<3;i++)
            arr[i]=cin.nextInt();
        n=0;
        Arrays.sort(arr);
        recursive(arr,0,N);
        System.out.println(n);
    }

    public static void recursive(int[] arr,int target,int N){
        if(target==N){
            n++;
            return;
        }
        if(target>N)
            return;
        for(int i=0;i<3;i++)
            recursive(arr,target+arr[i],N);
    }
}


IP 세그먼트 결합
import java.util.Scanner;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Comparator;
public class Main{
     
    static class Interval {
        int start;
        int end;
        Interval(int s, int e) { start = s; end = e; }
    }
     
    public static void main(String[] args){
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt(),start,end;
        ArrayList arr=new ArrayList<>();
        for(int i=0;i()
                        {
                            public int compare(Interval o1,Interval o2)
                            {
                                int k=o1.start-o2.start;
                                if(k==0)
                                    return o1.end-o2.end;
                                return k;
                            }
                        });
        LinkedList ans=new LinkedList<>();
        for(Interval tmp:arr)
        {
             
            if(ans.size()==0)
            {
                ans.add(tmp);
                continue;
            }
            Interval p=ans.getLast(); 
            if(p.end>=tmp.start)
                p.end=Math.max(p.end,tmp.end);
            else
                ans.add(tmp);
        }
        Iterator it=ans.iterator();
        while(it.hasNext()){
            Interval t=it.next();
            System.out.println(t.start+" "+t.end);
        }
    }
     
}


반복 시퀀스 찾기
public class Main5 {

    public static void print(ArrayList arr){
        for(int i=0;i> record=new HashMap<>();
        int n=cin.nextInt();
        for(int i=0;i tmp=new ArrayList<>();
                tmp.add(i);
                record.put(hash,tmp);
            }

        }
        int count=0;
        for(int i:record.keySet()){
            if(record.get(i).size()>1){
                print(record.get(i));
                count++;
            }
        }
        if(count==0)
            System.out.println("no");
    }
}

좋은 웹페이지 즐겨찾기