50 likes | 144 Views
Click to add title. Click to add lame programming pun. PotW Solution ( credits to Qingqi ).
E N D
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=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");
Take December USACO! • December 9-12 • You know you want to! • Even though it is the weekend before finals…
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.
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