1. 程式人生 > >2017光棍節新生訓練賽

2017光棍節新生訓練賽

組合 clas pro you while %d using scan continue

Description

There are some students in a class, Can you help teacher find the highest student .

Input

There are some cases. The first line contains an integer t, indicate the cases; Each case have an integer n ( 1 ≤ n ≤ 100 ) , followed n students’ height.

Output

For each case output the highest height, the height to two decimal plases;

Sample Input

2 3 170.00 165.00 180.00 4 165.00 182.00 172.00 160.00

Sample Output

180.00 182.00
//水題
#include<stdio.h>
int main()
{
int a,c,k,i;
double b;
double MAX=0.0;
scanf("%d",&c);
for(k=1;k<=c;k++)

{
double max=0.0;
scanf("%d",&a);
for(i=1;i<=a;i++)
{
scanf("%lf",&b); 
if(max<b)
max=b;
MAX
=max; } printf("%.2lf\n",MAX); } return 0; }

HDU 2567

#include<stdio.h>
#include<string.h>
int main()
{
    int i,x,y,c,d,z;
    char a[50],b[50];
    scanf("%d",&x);
    for(i=1;i<=x;i++)
    {
        scanf("%s",a);
        scanf("%s",b);
        c=strlen(a);
        d=strlen(b);
        
for(z=1,y=1;y<=(c/2);y++) { a[c+d-z]=a[c-z]; z++; } for(y=1;y<=d;y++) a[c/2+y-1]=b[y-1]; a[c+d]=\0; printf("%s\n",a); } }

HDU 2568

#include<stdio.h>
int main()
{
int a,n;
int A,B;

scanf("%d",&a);

for(int i=1;i<=a;i++)
{
A=0;B=0;
scanf("%d",&n);
while(n!=0)
{
    
    
    if(n%2==0)   //oushu
    {A++;
    n=n/2; 
    }
    else 
    {B++;
    n=n-1;
    }
    
 } 
 printf("%d\n",B);
}
 
return 0;

}

Description

假設一堆由1分、2分、5分組成的n個硬幣總面值為m分,求一共有多少種可能的組合方式(某種面值的硬幣可以數量可以為0)。

Input

輸入數據第一行有一個正整數T,表示有T組測試數據;
接下來的T行,每行有兩個數n,m,n和m的含義同上。

Output

對於每組測試數據,請輸出可能的組合方式數;
每組輸出占一行。

Sample Input

2 3 5 4 8

Sample Output

1 2
#include <stdio.h>
 
int main()
{
    int n, m, x, y, cnt, t, tmp, i;
    scanf("%d", &t);
    while(t--){
        scanf("%d%d", &n, &m);
        tmp = 5 * n - m;
        for(i = cnt = 0; i <= n; ++i)
            for(int j = 0; j <= n; ++j)
                if(4*i+3*j==tmp && i+j<=n)
                    ++cnt;
        printf("%d\n", cnt);
    }
    return 0;
}

HDU 5538

#include<cstdio>  
#include<algorithm>  
#include<string.h>  
#include<stdlib.h>  
#include<math.h>  
#define FIN freopen("in.txt","r",stdin)  
#define eps 1e-9  
using namespace std;  
int mp[55][55],cnt,n,m;  
int to[][2]={0,1,0,-1,1,0,-1,0};  
int main(){  
    int T;  
  //  FIN;  
    scanf("%d",&T);  
    while(T--){  
        scanf("%d%d",&n,&m);  
        int top=0;  
        cnt=0;  
        for(int i=0;i<n;i++)  
            for(int j=0;j<m;j++){  
                scanf("%d",&mp[i][j]);  
                top=max(top,mp[i][j]);  
                if(mp[i][j]) cnt++;  
                cnt+=mp[i][j]*4;  
            }  
        for(int x=0;x<n;x++){  
            for(int y=0;y<m;y++){  
                for(int i=0;i<4;i++){  
                    int xx=x+to[i][0],yy=y+to[i][1];  
                    if(xx<0||yy<0||xx>=n||yy>=m) continue;  
                    cnt-=min(mp[x][y],mp[xx][yy]);  
                }  
            }  
        }  
        printf("%d\n",cnt);  
    }  
    return 0;  
}  

 

2017光棍節新生訓練賽