數值統計
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 73 Accepted Submission(s) : 56
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
6 0 1 2 3 -1 0 5 1 2 3 4 0.5 0
Sample Output
1 2 3 0 0 5
Author
Source
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while(input.hasNext()){
int n=input.nextInt();
if(n==0)
break;
int a=0,b=0,c=0;
while(n-->0){
float s=input.nextFloat();
if(s==0)
b++;
if(s<0)
a++;
if(s>0)
c++;
}
System.out.println(a+" "+b+" "+c);
}
}
}
數塔
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 55 Accepted Submission(s) : 33
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
有如下所示的數塔,要求從頂層走到底層,若每一步只能走到相鄰的結點,則經過的結點的數字之和最大是多少?
已經告訴你了,這是個DP的題目,你能AC嗎?
Input
Output
Sample Input
1 5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
Sample Output
30
Source
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Scanner input=new Scanner(System.in);
//BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
Scanner input=new Scanner(System.in);
int N=input.nextInt();
while(N-->0){
int c=input.nextInt();
int a[][]=new int[c][c];
a[0][0]=input.nextInt();
for(int i=1;i<c;i++){
for(int j=0;j<=i;j++){
a[i][j]=input.nextInt();
}
}
for(int i=1;i<c;i++){
a[i][0]+=a[i-1][0];
for(int j=1;j<i;j++){
a[i][j]+=a[i-1][j-1]>a[i-1][j]?a[i-1][j-1]:a[i-1][j];
}
a[i][i]+=a[i-1][i-1];
}
int sum=a[c-1][0];
for(int i=1;i<c;i++){
if(sum<a[c-1][i]){
sum=a[c-1][i];
}
}
System.out.println(sum);
/*for(int i=0;i<c;i++){
for(int j=0;j<=i;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}*/
}
}
}
蟠桃記
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 75 Accepted Submission(s) : 54
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
什麼問題?他研究的問題是蟠桃一共有多少個!
不過,到最後,他還是沒能解決這個難題,呵呵^-^
當時的情況是這樣的:
第一天悟空喫掉桃子總數一半多一個,第二天又將剩下的桃子喫掉一半多一個,以後每天喫掉前一天剩下的一半多一個,
Input
Output
Sample Input
2 4
Sample Output
4 22
Author
Source
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while(input.hasNext()){
int n=input.nextInt();
long sum=1;
for(int i=1;i<n;i++){
sum=(sum+1)*2;
}
System.out.println(sum);
}
}
}
七夕節
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 171 Accepted Submission(s) : 39
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
人們紛紛來到告示前,都想知道誰纔是自己的另一半.告示如下:
數字N的因子就是所有比N小又能被N整除的所有正整數,如12的因子有1,2,3,4,6.
你想知道你的另一半嗎?
Input
Output
Sample Input
3 2 10 20
Sample Output
1 8 22
Author
Source
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
// Scanner input=new Scanner(System.in);
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
try {
int N=Integer.parseInt(bf.readLine());
while(N-->0){
int n=Integer.parseInt(bf.readLine());
long sum=1;
int i=0;
for(i=2;i*i<=n;i++){
if(n%i==0){
sum+=i+n/i;
}
}
if((i-1)*(i-1)==n)
sum-=Math.sqrt(n);
System.out.println(sum);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
六度分離
Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 36 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Lele對這個理論相當有興趣,於是,他在HDU裏對N個人展開了調查。他已經得到了他們之間的相識關係,
Input
對於每組測試,第一行包含兩個整數N,M(0<N<100,0<M<200),分別代表HDU裏的人數
除了這M組關係,其他任意兩人之間均不相識。
Output
Sample Input
8 7 0 1 1 2 2 3 3 4 4 5 5 6 6 7 8 8 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 0
Sample Output
Yes Yes
Author
Source
/*
* 相當於求最短路徑是否小於等於7
*
*/
import java.util.Arrays;
import java.util.Scanner;
public class Main{
static int Max=100000;
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while(input.hasNext()){
int n=input.nextInt();
int m=input.nextInt();
int map[][]=new int[n][n];
for(int i=0;i<n;i++){
Arrays.fill(map[i], Max);
map[i][i]=0;
}
for(int i=0;i<m;i++){
int a=input.nextInt();
int b=input.nextInt();
map[a][b]=map[b][a]=1;
}
for(int k=0;k<n;k++){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(map[j][i]>map[j][k]+map[k][i])
map[j][i]=map[j][k]+map[k][i];
}
}
}
int min=0;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(min<map[i][j])
min=map[i][j];
}
}
if(min<=7)
System.out.println("Yes");
else
System.out.println("No");
}
}
}