5
Click to add title Click to add lame programming pun

Click to add title Click to add lame programming pun

Embed Size (px)

Citation preview

Page 1: Click to add title Click to add lame programming pun

Click to add title

Click to add lame programming pun

Page 2: Click to add title Click to add lame programming pun

PotW Solution (credits to Qingqi)Scanner input=new Scanner(System.in);int v=input.nextInt(), e=input.nextInt();ArrayList<Integer>[] g=new ArrayList[v];for(int i=0;i<v;i++) g[i]=new ArrayList<Integer>();for(int i=0;i<e;i++) {   int a=input.nextInt()-1, b=input.nextInt()-1;   g[a].add(b);   g[b].add(a);}boolean[] visited=new boolean[v];Queue<Integer> q=new LinkedList<Integer>();q.offer(0);visited[0]=true;int cnt=1;while(!q.isEmpty()) {   int node=q.poll();   for(int n: g[node]) {          if(!visited[n]) {                 visited[n]=true;                 q.add(n);                 cnt++;          }   }}System.out.println(e==v-1 && cnt==v?"YES":"NO");

Page 3: Click to add title Click to add lame programming pun

Take December USACO!

• December 9-12• You know you want to!

o Even though it is the weekend before finals…

Page 4: Click to add title Click to add lame programming pun

PotW - Cow Trails• Farmer John wants to create a scenic trail on his field, and has

hired you. To maximize your pay, make the trail as long as possible.

• However, his field has trees on it, and he refuses to cut them down because he is environmentally conscious. Trees are denoted with "Y", and empty spaces are denoted with ".".

• The trail starts at the top left corner and cannot intersect with itself (it is NOT a loop)

Sample Input:                   Sample Output (not optimal):4 5    (rows columns)     RRRRDLLDDLULD......Y......Y......

The time limit is 10 seconds, and the dimensions of the grid are less than 80. Scoring will be relative to your placing out of all submissions: the kth best will receive 54-3*k points, with ties rounding up.

Page 5: Click to add title Click to add lame programming pun

Hints• Use System.currentTimeMillis() to make sure your

program is done by the end of 10 seconds• Try using a random number generator along with

multiple trials to get a better solutiono Note that only your final solution will be graded, so there may be a

small amount of luck involved here

• To improve your solution, try making some random test caseso The actual test data will be randomly generated, with a 3x3 empty

space at the top left corner, and less than 40% trees

• GO!o You have three weeks to outdo your competitors

• Rest of the meeting is for discussion/studying