Poj3320 (ruler acquisition) and poj3320
N number. The minimum interval overwrites all the different numbers in n number.
Solution:
AC code:
Import java. util. hashMap; import java. util. hashSet; import java. util. map; import java. util. imports; import java. util. set; public class Main {/*** @ param args */static int n; static Set <Integer> set = new HashSet <Integer> (); static int a [] = new int [1000000 + 2]; static Map <Integer, Integer> map = new HashMap <Integer, Integer> (); public static void main (String [] args) {// TODO Auto-generated method stub1_scan = new dynamic (System. in); n = scan. nextInt (); for (int I = 0; I <n; I ++) {set. add (a [I] = scan. nextInt ();} int size = set. size (); // calculate the number of different knowledge points int start = 0, end = 0, sum = 0; int res = n; (;;) {while (end <n & sum <size) {Integer cnt = map. get (a [end]); if (cnt = null) {sum ++; map. put (a [end], 1);} else map. put (a [end], cnt + 1); end ++;} if (sum <size) break; res = Math. min (end-start, res); int cnt = map. get (a [start]); if (cnt = 1) {map. remove (a [start]); sum --;} else map. put (a [start], cnt-1); start ++;} System. out. println (res );}}