第一次(40)
最后证明:和输入超时无关,和long类型无关.
package csp;
//long 类型
//scanner 读取超时?
//4
//4 74 -7 -12 -5
//5 73 -8 -6 59 -4
//5 76 -5 -10 60 -2
//5 80 -6 -15 59 0
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long[][] a = new long[n][3];
int T=0,D=0,E=0;
for(int i =0;i<n;i++) {
int m = in.nextInt();
a[i][0] = in.nextLong();
boolean flag = true;
for(int j =1;j<m;j++) {
//long temp = in.nextInt();
long temp = in.nextLong();
if(flag) {
if(temp<=0) a[i][0] += temp;
if(temp>0) {
a[i][1] = temp;//记录同一棵树统计第二次时的果数
flag = false;
}
}
if(!flag) {
a[i][2] += temp;//累加同一棵树统计第二次时的果数
}
}
if(a[i][1] == 0 && a[i][0] !=0 ) {
a[i][1] = a[i][0];//补齐 方便后值计算
a[i][2] = a[i][0];
}
}//for
in.close();
for(int i =0;i<n;i++) {
T+=a[i][2];
if(a[i][0] - a[i][1] > 0) {D++; //落果棵树
//System.out.println(i+" "+a[i][0]+" "+a[i][1]);
}
//统计组数
if(i==0) {
if((a[i][0]-a[i][1] > 0) && (a[n-1][0]-a[n-1][1] > 0) && (a[i+1][0]-a[i+1][1] > 0)) {
E ++;
}
}
if(i == n-1) {
if((a[i][0]-a[i][1] > 0) && (a[i-1][0]-a[i-1][1] > 0) && (a[0][0]-a[0][1] > 0)) {
E ++;
}
}
if(i >0 && i< n-1) {
if((a[i][0]-a[i][1] > 0) && (a[i-1][0]-a[i-1][1] > 0) && (a[i+1][0]-a[i+1][1] > 0)) {
E ++;
}
}
}
System.out.print(T+" "+D+" "+E);
}
}
//5
//4 10 0 9 0
//4 10 -2 7 0
//2 10 0
//4 10 -3 5 0
//4 20 -1 8 0
第二次(100)
//4
//4 74 -7 -12 -5
//5 73 -8 -6 59 -4
//5 76 -5 -10 60 -2
//5 80 -6 -15 59 0
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();//in.nextInt()之后再读一下 以进入到输入n的下一行,否则会出错
int[] a = new int[n+2];//直接将前两个值放到后面 减少了分情况讨论
int T=0,D=0,E=0;
for(int i =0;i<n;i++) {
String line = in.nextLine();
String[] s = line.trim().split(" "); // 去除多余空格、再以空格分割数字
int m = Integer.parseInt(s[0]);// String 转int
int currentcount = Integer.parseInt(s[1]);// String 转int
boolean flag = false;
for(int j =2;j<=m;j++) {
int temp = Integer.parseInt(s[j]);
if(temp > 0) {//重新计数
if(currentcount > temp && !flag) {//看是否落果
flag = true;
a[i] = 1;//记录当前位置表示落果了
D++;//记录棵树
}
currentcount = temp; //不论是否落果 该值都要更新
}else {//落果累加
currentcount += temp;
}
}
T += currentcount ;//总数目累加
}//for
in.close();
a[n] = a[0];//绕后
a[n+1] = a[1];
for(int i =1;i<n+1;i++) {
if(a[i] == 1 && a[i-1] == 1 && a[i+1] == 1) {//相邻三棵树发生落果
E++;
}
}
System.out.print(T+" "+D+" "+E);
}
}
//5
//4 10 0 9 0
//4 10 -2 7 0
//2 10 0
//4 10 -3 5 0
//4 20 -1 8 0