1 / 5

Click to add title

Click to add title. Click to add lame programming pun. PotW Solution ( credits to Qingqi ).

fiona
Download Presentation

Click to add title

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Click to add title Click to add lame programming pun

  2. PotW Solution(credits to Qingqi) Scanner input=new Scanner(System.in);int v=input.nextInt(), e=input.nextInt();ArrayList<Integer>[] g=newArrayList[v];for(inti=0;i<v;i++) g[i]=newArrayList<Integer>();for(inti=0;i<e;i++) {int a=input.nextInt()-1, b=input.nextInt()-1;   g[a].add(b);   g[b].add(a);}boolean[] visited=newboolean[v];Queue<Integer> q=newLinkedList<Integer>();q.offer(0);visited[0]=true;intcnt=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");

  3. Take December USACO! • December 9-12 • You know you want to! • Even though it is the weekend before finals…

  4. 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.

  5. 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 solution • 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 cases • The actual test data will be randomly generated, with a 3x3 empty space at the top left corner, and less than 40% trees • GO! • You have three weeks to outdo your competitors • Rest of the meeting is for discussion/studying

More Related