git reimport
This commit is contained in:
BIN
dcj/other/pancakes.class
Normal file
BIN
dcj/other/pancakes.class
Normal file
Binary file not shown.
25
dcj/other/pancakes.java
Normal file
25
dcj/other/pancakes.java
Normal file
@@ -0,0 +1,25 @@
|
||||
// Sample input 2, in Java.
|
||||
public class pancakes {
|
||||
public pancakes() {
|
||||
}
|
||||
|
||||
public static long GetStackSize() {
|
||||
return 6L;
|
||||
}
|
||||
|
||||
public static long GetNumDiners() {
|
||||
return 4L;
|
||||
}
|
||||
|
||||
public static long GetStackItem(long i) {
|
||||
switch ((int)i) {
|
||||
case 0: return 0L;
|
||||
case 1: return 0L;
|
||||
case 2: return 0L;
|
||||
case 3: return 2L;
|
||||
case 4: return 2L;
|
||||
case 5: return 3L;
|
||||
default: throw new IllegalArgumentException("Invalid argument");
|
||||
}
|
||||
}
|
||||
}
|
23
dcj/other/pancakes0.java
Normal file
23
dcj/other/pancakes0.java
Normal file
@@ -0,0 +1,23 @@
|
||||
// Sample input 1, in Java.
|
||||
public class pancakes0 {
|
||||
public pancakes0() {
|
||||
}
|
||||
|
||||
public static long GetStackSize() {
|
||||
return 4L;
|
||||
}
|
||||
|
||||
public static long GetNumDiners() {
|
||||
return 4L;
|
||||
}
|
||||
|
||||
public static long GetStackItem(long i) {
|
||||
switch ((int)i) {
|
||||
case 0: return 3L;
|
||||
case 1: return 1L;
|
||||
case 2: return 2L;
|
||||
case 3: return 0L;
|
||||
default: throw new IllegalArgumentException("Invalid argument");
|
||||
}
|
||||
}
|
||||
}
|
25
dcj/other/pancakes1.java
Normal file
25
dcj/other/pancakes1.java
Normal file
@@ -0,0 +1,25 @@
|
||||
// Sample input 2, in Java.
|
||||
public class pancakes1 {
|
||||
public pancakes1() {
|
||||
}
|
||||
|
||||
public static long GetStackSize() {
|
||||
return 6L;
|
||||
}
|
||||
|
||||
public static long GetNumDiners() {
|
||||
return 4L;
|
||||
}
|
||||
|
||||
public static long GetStackItem(long i) {
|
||||
switch ((int)i) {
|
||||
case 0: return 0L;
|
||||
case 1: return 0L;
|
||||
case 2: return 0L;
|
||||
case 3: return 2L;
|
||||
case 4: return 2L;
|
||||
case 5: return 3L;
|
||||
default: throw new IllegalArgumentException("Invalid argument");
|
||||
}
|
||||
}
|
||||
}
|
26
dcj/other/pancakes2.java
Normal file
26
dcj/other/pancakes2.java
Normal file
@@ -0,0 +1,26 @@
|
||||
// Sample input 3, in Java.
|
||||
public class pancakes2 {
|
||||
public pancakes2() {
|
||||
}
|
||||
|
||||
public static long GetStackSize() {
|
||||
return 7L;
|
||||
}
|
||||
|
||||
public static long GetNumDiners() {
|
||||
return 5L;
|
||||
}
|
||||
|
||||
public static long GetStackItem(long i) {
|
||||
switch ((int)i) {
|
||||
case 0: return 0L;
|
||||
case 1: return 1L;
|
||||
case 2: return 3L;
|
||||
case 3: return 2L;
|
||||
case 4: return 1L;
|
||||
case 5: return 3L;
|
||||
case 6: return 0L;
|
||||
default: throw new IllegalArgumentException("Invalid argument");
|
||||
}
|
||||
}
|
||||
}
|
87
dcj/other/pancakes_solution.java
Normal file
87
dcj/other/pancakes_solution.java
Normal file
@@ -0,0 +1,87 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Main().run();
|
||||
}
|
||||
|
||||
int myId = message.MyNodeId();
|
||||
int nodeCount = message.NumberOfNodes();
|
||||
long stackSize = pancakes.GetStackSize();
|
||||
long diners = pancakes.GetNumDiners();
|
||||
long perNode = stackSize / nodeCount + 1;
|
||||
|
||||
long iL = myId * perNode;
|
||||
long iR = Math.min((myId + 1) * perNode, stackSize);
|
||||
|
||||
void run() {
|
||||
client();
|
||||
|
||||
if (myId == 0) {
|
||||
server();
|
||||
}
|
||||
}
|
||||
|
||||
long count(List<Long> xs) {
|
||||
long res = 0;
|
||||
long prev = -1;
|
||||
for (Long x : xs) {
|
||||
if (x < prev) {
|
||||
res++;
|
||||
}
|
||||
prev = x;
|
||||
}
|
||||
return res + 1;
|
||||
}
|
||||
|
||||
void client() {
|
||||
List<Long> xs = new ArrayList<>();
|
||||
for (long i = iL; i < iR; i++) {
|
||||
long x = pancakes.GetStackItem(i);
|
||||
xs.add(x);
|
||||
}
|
||||
|
||||
if (xs.isEmpty()) {
|
||||
message.PutLL(0, -1);
|
||||
message.Send(0);
|
||||
return;
|
||||
}
|
||||
|
||||
long res = count(xs);
|
||||
|
||||
message.PutLL(0, xs.get(0));
|
||||
message.PutLL(0, xs.get(xs.size() - 1));
|
||||
message.PutLL(0, res);
|
||||
message.Send(0);
|
||||
}
|
||||
|
||||
void server() {
|
||||
long res = 0;
|
||||
long prevLast = Long.MAX_VALUE;
|
||||
|
||||
for (int nodeId = 0; nodeId < nodeCount; nodeId++) {
|
||||
message.Receive(nodeId);
|
||||
long first = message.GetLL(nodeId);
|
||||
if (first == -1) {
|
||||
continue;
|
||||
}
|
||||
long last = message.GetLL(nodeId);
|
||||
long iRes = message.GetLL(nodeId);
|
||||
|
||||
// System.out.println("R " + nodeId + ": "+ first + " " + last + " " + iRes);
|
||||
|
||||
res += iRes;
|
||||
|
||||
if (prevLast <= first) {
|
||||
res--;
|
||||
}
|
||||
prevLast = last;
|
||||
|
||||
// System.out.println(res);
|
||||
}
|
||||
|
||||
System.out.println(res);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user