【LDU】新生训练营杭电100题(二)

A - 发工资咯:) 

http://acm.hdu.edu.cn/showproblem.php?pid=2021

Problem Description
作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵
但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每个老师的工资额都知道,最少需要准备多少张人民币,才能在给每位老师发工资的时候都不用老师找零呢?
这里假设老师的工资都是正整数,单位元,人民币一共有100元、50元、10元、5元、2元和1元六种。
 

Input
输入数据包含多个测试实例,每个测试实例的第一行是一个整数n(n<100),表示老师的人数,然后是n个老师的工资。
n=0表示输入的结束,不做处理。
 

Output
对于每个测试实例输出一个整数x,表示至少需要准备的人民币张数。每个输出占一行。
 

Sample Input
  
  
3 1 2 3 0
 

Sample Output
  
  
4

#include<stdio.h>
#include<stdlib.h>
int a[6]={100,50,10,5,2,1};
int main()
{
       int n;
       while(~scanf("%d",&n),n)
       {
           int *b,sum=0,i,j,k;
           b=(int *)calloc(n,sizeof(int));
           for(i=0;i<n;i++)
           {
                scanf("%d",b+i);
                for(j=0;j<6;j++)
                {
                    sum+=b[i]/a[j];
                    b[i]=b[i]%a[j];
                }
           }
           printf("%d\n",sum);
       }
       return 0;
}

B - 海选女主角

http://acm.hdu.edu.cn/showproblem.php?pid=2022

Problem Description
potato老师虽然很喜欢教书,但是迫于生活压力,不得不想办法在业余时间挣点外快以养家糊口。
“做什么比较挣钱呢?筛沙子没力气,看大门又不够帅...”potato老师很是无奈。
“张艺谋比你还难看,现在多有钱呀,听说还要导演奥运开幕式呢!你为什么不去娱乐圈发展呢?”lwg在一旁出主意。
嗯,也是,为了生存,就委屈点到娱乐圈混混吧,马上就拍一部激光电影《杭电记忆——回来我的爱》。
说干就干,马上海选女主角(和老谋子学的,此举可以吸引媒体的眼球,呵呵),并且特别规定,演员必须具有ac的基本功,否则直接out!
由于策划师风之鱼(大师级水王)宣传到位,来应聘的MM很多,当然包括nit的蛋糕妹妹等呼声很高的美女,就连zjut的jqw都男扮女装来应聘(还好被安全顾问hdu_Bin-Laden认出,给轰走了),看来娱乐圈比acm还吸引人哪...
面试那天,刚好来了m*n个MM,站成一个m*n的队列,副导演Fe(OH)2为每个MM打了分数,分数都是32位有符号整数。
一开始我很纳闷:分数怎么还有负的?Fe(OH)2解释说,根据选拔规则,头发染成黄色、化妆太浓、穿的太少等等都要扣分数的,扣的多了就可能是负分了,当然,如果发现话语中夹有日语,就直接给-2147483648分了。
分数送上来了,是我做决定的时候了,我的一个选拔原则是,要选一个面试分数绝对值(必须还是32位整数)最大的MM。
特别说明:如果不幸选中一个负分的MM,也没关系,因为我觉得,如果不能吸引你,那要想法恶心你。
 

Input
输入数据有多组,每组的第一行是两个整数m和n,表示应聘MM的总共的行列数,然后是m行整数,每行有n个,m和n的定义见题目的描述。
 

Output
对于每组输入数据,输出三个整数x,y和s,分别表示选中的MM的行号、列号和分数。
note:行号和列号从一开始,如果有多个MM的分数绝对值一样,那么输出排在最前面的一个(即行号最小的那个,如果行号相同则取列号最小的那个)。 
 

Sample Input
  
  
2 3 1 4 -3 -7 3 0
 

Sample Output
  
  
2 1 -7


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int n,m,row,col,maxz;
void solve(int a[][100])
{
      maxz=a[0][0];row=col=0;
      int i,j;
      for(i=0;i<n;i++)
      {
          for(j=0;j<m;j++)
          {
              if(fabs(maxz)<fabs(a[i][j]))
              {
                  maxz=a[i][j];
                  row=i;
                  col=j;
              }
          }
      }
      printf("%d %d %d\n",row+1,col+1,maxz);
}
int main()
{
       while(~scanf("%d%d",&n,&m))
       {
            int i,j;
            int a[100][100];
            for(i=0;i<n;i++)
                for(j=0;j<m;j++)
                    scanf("%d",&a[i][j]);
            solve(a);
       }
       return 0;

}


C - 求平均成绩 

https://vjudge.net/problem/26705/origin

Problem Description
假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量。
 

Input
输入数据有多个测试实例,每个测试实例的第一行包括两个整数n和m,分别表示学生数和课程数。然后是n行数据,每行包括m个整数(即:考试分数)。
 

Output
对于每个测试实例,输出3行数据,第一行包含n个数据,表示n个学生的平均成绩,结果保留两位小数;第二行包含m个数据,表示m门课的平均成绩,结果保留两位小数;第三行是一个整数,表示该班级中各科成绩均大于等于平均成绩的学生数量。
每个测试实例后面跟一个空行。
 

Sample Input
  
  
2 2 5 10 10 20
 

Sample Output
  
  
7.50 15.00 7.50 15.00 1
 
#include<stdio.h>
#define N 50
#define M 5
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
          int i,j;
          double xueke[6]={0},tongxue[51]={0};
          double a[51][6];
          for(i=0;i<n;i++)
          {
               for(j=0;j<m;j++)
               {
                  scanf("%lf",&a[i][j]);
               }
          }
          for(i=0;i<n;i++)
          {
              for(j=0;j<m;j++)
              {
                  tongxue[i]+=a[i][j];
              }
              tongxue[i]/=(double)m;
          }
          for(j=0;j<m;j++)
          {
              for(i=0;i<n;i++)
              {
                   xueke[j]+=a[i][j];
              }
              xueke[j]/=(double)n;
          }
          int sum=0;
          for(i=0;i<n;i++)
          {
              int count=0;
              for(j=0;j<m;j++)
              {
                  if(a[i][j]>=xueke[j])
                  {
                     count++;
                  }
              }
              if(count==m)
              {
                  sum++;
              }
          }
          for(i=0;i<n;i++)
          {
              printf(i==n-1?"%.2lf\n":"%.2lf ",tongxue[i]);
          }
          for(j=0;j<m;j++)
          {
              printf(j==m-1?"%.2lf\n":"%.2lf ",xueke[j]);
          }
          printf("%d\n\n",sum);

    }
    return 0;
}


D - C语言合法标识符 

http://acm.hdu.edu.cn/showproblem.php?pid=2024

Problem Description
输入一个字符串,判断其是否是C的合法标识符。
 

Input
输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。
 

Output
对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。
 

Sample Input
  
  
3 12ajf fi8x_a ff ai_2
 

Sample Output
  
  
no yes no
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
     int T;
     scanf("%d",&T);
     getchar();
     while(T--)
     {
          int i,flag=1;
          char str[60];

          gets(str);
          if((str[0]!='_')&&(!isalpha(str[0])))
          {
               flag=0;
          }
          for(i=1;i<strlen(str)&&flag;i++)
          {
              if(str[i]!='_'&&(!isdigit(str[i]))&&(!isalpha(str[i])))
               {
                   flag=0;
               }
          }
          if(flag)
          {
             printf("yes\n");
          }
          else
          {
             printf("no\n");
          }

     }
}


E - 查找最大元素 

http://acm.hdu.edu.cn/showproblem.php?pid=2025

Problem Description
对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。
 

Input
输入数据包括多个测试实例,每个实例由一行长度不超过100的字符串组成,字符串仅由大小写字母构成。
 

Output
对于每个测试实例输出一行字符串,输出的结果是插入字符串“(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入"(max)"。
 

Sample Input
  
  
abcdefgfedcba xxxxx
 

Sample Output
  
  
abcdefg(max)fedcba x(max)x(max)x(max)x(max)x(max)
 

#include<stdio.h>
#include<string.h>
int main()
{
    char str[150];
    while(~scanf("%s",str))
    {
        int i,a[100]={0},maxz=str[0];
        for(i=0;i<strlen(str);i++)
        {
             if(maxz<str[i])
             {
                 maxz=str[i];
                 memset(a,0,sizeof(a));
                 a[i]=1;
             }
             else if(maxz==str[i])
             {
                 a[i]=1;
             }
        }
        for(i=0;i<strlen(str);i++)
        {
             printf("%c",str[i]);
             if(a[i]==1)
                printf("(max)");
            if(i==strlen(str)-1)
               printf("\n");
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
      char n,i,str[100];
      while(~scanf("%s",str))
      {
           int ans[100]={0};
           char maxz=str[0];
           for(i=0;str[i]!='\0';i++)
           {
                 if(maxz<str[i])
                 {
                    maxz=str[i];
                 }
           }
           for(i=0;str[i]!='\0';i++)
           {
                if(maxz==str[i])
                {
                    ans[i]=1;
                }
           }
           for(i=0;str[i]!='\0';i++)
           {
               printf("%c",str[i]);
               if(ans[i]==1)
                  printf("(max)");
           }
           printf("\n");
      }
}

F - 首字母变大写 

http://acm.hdu.edu.cn/showproblem.php?pid=2026

Problem Description
输入一个英文句子,将每个单词的第一个字母改成大写字母。
 

Input
输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。
 

Output
请输出按照要求改写后的英文句子。
 

Sample Input
  
  
i like acm i want to get an accepted
 

Sample Output
  
  
I Like Acm I Want To Get An Accepted
 


#include<stdio.h>
#include<string.h>
int main()
{
     int i;
     char str[150];
     while(gets(str))
     {
          for(i=0;i<strlen(str);i++)
          {
              if(i==0||str[i-1]==' ')
                 printf("%c",str[i]-32);
              else
                 printf("%c",str[i]);
          }
          printf("\n");
     }
     return 0;
}

G - 统计元音 

Problem Description
统计每个元音字母在字符串中出现的次数。
 

Input
输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串。
 

Output
对于每个测试实例输出5行,格式如下:
a:num1
e:num2
i:num3
o:num4
u:num5
多个测试实例之间由一个空行隔开。

请特别注意:最后一块输出后面没有空行:)
 

Sample Input
  
  
2 aeiou my name is ignatius
 

Sample Output
  
  
a:1 e:1 i:1 o:1 u:1 a:2 e:1 i:3 o:0 u:1
 

#include<stdio.h>
#include<string.h>
#include<map>
using namespace std;
int main()
{
     map<int,char> my;
     my[1]='a';
     my[2]='e';
     my[3]='i';
     my[4]='o';
     my[5]='u';
   int T;
    scanf("%d",&T);
    getchar();
        while(T--)
      {

         char str[150];
         int a[27]={0};
         int i;
         gets(str);

           for(i=0;i<strlen(str);i++)
           {
                a[str[i]-'a']++;
           }

           for(i=1;i<=5;i++)
           {
              printf("%c:%d\n", my[i] ,a[my[i]-'a'] );
           }
           if(T)
           printf("\n");
        }
     return 0;

}

H - Lowest Common Multiple Plus 

http://acm.hdu.edu.cn/showproblem.php?pid=2028

Problem Description
求n个数的最小公倍数。
 

Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
 

Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
 

Sample Input
  
  
2 4 6 3 2 5 7
 

Sample Output
  
  
12 70

#include<stdio.h>
int res(int a,int b)
{
     return a%b==0?b:res(b,a%b);
}
int main()
{
      int n;
      while(~scanf("%d",&n))
      {
          int i,a,b;
            scanf("%d",&a);
          for(i=1;i<n;i++)
          {
              scanf("%d",&b);
              a=a/res(a,b)*b;
          }
          printf("%d\n",a);
      }
      return 0;
}

I - Palindromes _easy version 

http://acm.hdu.edu.cn/showproblem.php?pid=2029

Problem Description
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
 

Input
输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。
 

Output
如果一个字符串是回文串,则输出"yes",否则输出"no".
 

Sample Input
  
  
4 level abcde noon haha
 

Sample Output
  
  
yes no yes no

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        string a,b;
        cin>>a;
        b=a;
        reverse(a.begin(),a.end());
        if(a==b)
            cout<<"yes"<<endl;
        else
            cout<<"no"<<endl;
    }
}

J - 汉字统计 

http://acm.hdu.edu.cn/showproblem.php?pid=2030

Problem Description
统计给定文本文件中汉字的个数。
 

Input
输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。
 

Output
对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。

[Hint:]从汉字机内码的特点考虑~

 

Sample Input
  
  
2 WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa! 马上就要期末考试了Are you ready?
 

Sample Output
  
  
14 9
#include<stdio.h>
#include<string.h>

int main()
{
	char a[100001];
	int n;
	int i;
	int s;
	scanf("%d",&n);
	getchar();
	while(n--)
	{
       gets(a);
	   s=0;
	   for(i=0;i<strlen(a);i++)
	   {
		   if(a[i]<0)
			 s++;
	   }
	   printf("%d\n",s/2);
	}
	return 0;
}

K - 进制转换 

http://acm.hdu.edu.cn/showproblem.php?pid=2031

Problem Description
输入一个十进制数N,将它转换成R进制数输出。
 

Input
输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16, R<>10)。
 

Output
为每个测试实例输出转换后的数,每个输出占一行。如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等)。
 

Sample Input
  
  
7 2 23 12 -4 3
 

Sample Output
  
  
111 1B -11

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
         char str[16]={'0','1','2','3','4','5','6'
         ,'7','8','9','A','B','C','D','E','F'};
         char ans[1000]={'\0'};
         int count=0,i,t=abs(n);
         while(t)
         {
             ans[count++]=str[t%k];
             t/=k;
         }
         if(n<0)
            printf("-");

         for(i=count-1;i>=0;i--)
         {
             printf("%c",ans[i]);
         }
         printf("\n");

    }
    return 0;
}

L - 杨辉三角 

http://acm.hdu.edu.cn/showproblem.php?pid=2032

Problem Description
还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
 

Input
输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。
 

Output
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
 

Sample Input
  
  
2 3
 

Sample Output
  
  
1 1 1 1 1 1 1 2 1
#include<stdio.h>
int ans[35][35]={0};
void solve()
{
    int i,j;
    for(i=0;i<=31;i++)
    {
          for(j=0;j<=i;j++)
          {
             if(j==i||j==0)
                ans[i][j]=1;
             else
             {
                ans[i][j]=ans[i-1][j-1]+ans[i-1][j];
             }
          }
    }
}
int main()
{
    int n,i,j;
    solve();
    while(~scanf("%d",&n))
    {

         for(i=0;i<n;i++)
         {
             for(j=0;j<=i;j++)
             {
                printf(j==i?"%d\n":"%d ",ans[i][j]);
             }
         }
         printf("\n");
    }
    return 0;
}

M - 人见人爱A+B 

http://acm.hdu.edu.cn/showproblem.php?pid=2033

Problem Description
HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱。
这个题目的A和B不是简单的整数,而是两个时间,A和B 都是由3个整数组成,分别表示时分秒,比如,假设A为34 45 56,就表示A所表示的时间是34小时 45分钟 56秒。
 

Input
输入数据有多行组成,首先是一个整数N,表示测试实例的个数,然后是N行数据,每行有6个整数AH,AM,AS,BH,BM,BS,分别表示时间A和B所对应的时分秒。题目保证所有的数据合法。
 

Output
对于每个测试实例,输出A+B,每个输出结果也是由时分秒3部分组成,同时也要满足时间的规则(即:分和秒的取值范围在0~59),每个输出占一行,并且所有的部分都可以用32位整数表示。
 

Sample Input
  
  
2 1 2 3 4 5 6 34 45 56 12 23 34
 

Sample Output
  
  
5 7 9 47 9 30

#include<stdio.h>
#include<string.h>
int main()
{
   int n,i,t;
   int shi1,fen1,miao1,shi2,fen2,miao2;
   scanf("%d",&t);
   while(t--)
   {
        scanf("%d %d %d %d %d %d",&shi1,&fen1,&miao1,&shi2,&fen2,&miao2);
        int shi=0,fen=0,miao=0;
        if(miao1+miao2>=60)
        {
           miao=(miao1+miao2)%60;
           fen+=1;
        }
        else
        {
           miao=miao1+miao2;
        }
        if(fen1+fen2+fen>=60)
        {
            fen=(fen1+fen2+fen)%60;
            shi+=1;
        }
        else
        {
            fen=fen1+fen2+fen;
        }
        shi=shi1+shi2+shi;
        printf("%d %d %d\n",shi,fen,miao);
   }
   return 0;
}
N - 人见人爱A-B 

Problem Description
参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法运算。(当然,大家都知道集合的定义,就是同一个集合中不会有两个相同的元素,这里还是提醒大家一下)

呵呵,很简单吧?
 

Input
每组输入数据占1行,每行数据的开始是2个整数n(0<=n<=100)和m(0<=m<=100),分别表示集合A和集合B的元素个数,然后紧跟着n+m个元素,前面n个元素属于集合A,其余的属于集合B. 每个元素为不超出int范围的整数,元素之间有一个空格隔开.
如果n=0并且m=0表示输入的结束,不做处理。
 

Output
针对每组数据输出一行数据,表示A-B的结果,如果结果为空集合,则输出“NULL”,否则从小到大输出结果,为了简化问题,每个元素后面跟一个空格.
 

Sample Input
  
  
3 3 1 2 3 1 4 7 3 7 2 5 8 2 3 4 5 6 7 8 0 0
 

Sample Output
  
  
2 3 NULL
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
     int n,m;
     while(~scanf("%d%d",&n,&m),(n||m))
     {
          int a[120],b[120],c[120],i,j,count=0;
          for(i=0;i<n;i++)
          {
              scanf("%d",&a[i]);
              c[i]=i;
          }
          for(i=0;i<m;i++)
          {
              scanf("%d",&b[i]);
          }
          sort(a,a+n);
          for(i=0;i<n;i++)
          {
               for(j=0;j<m;j++)
               {
                  if(a[i]==b[j])
                  {
                      c[i]=-1;
                      count++;
                  }
               }
          }
          if(count==n)
          {
              printf("NULL\n");
          }
          else
          {
              for(i=0;i<n;i++)
              {
                  if(c[i]!=-1)
                  {

                     printf("%d ",a[i]);

                  }
              }
              putchar('\n');
          }

     }
     return 0;
}
O - 人见人爱A^B 

http://acm.hdu.edu.cn/showproblem.php?pid=2035

Problem Description
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
 

Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
 

Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
 

Sample Input
  
  
2 3 12 6 6789 10000 0 0
 

Sample Output
  
  
8 984 1
#include<stdio.h>
const int mod=1000;
typedef long long ll;
ll qpow(ll a ,ll b)
{
      ll ans=1;
      while(b)
      {
           if(b&1)
              ans=(ans*a)%mod;
           a=(a*a)%mod;
           b/=2;
      }
      return ans;
}
int main()
{
      ll n,m;
      while(~scanf("%lld%lld",&n,&m),(n||m))
      {
           printf("%lld\n",qpow(n,m));
      }
      return 0;
}

P - 改革春风吹满地 

http://acm.hdu.edu.cn/showproblem.php?pid=2036

Problem Description
“ 改革春风吹满地,
不会AC没关系;
实在不行回老家,
还有一亩三分地。
谢谢!(乐队奏乐)”

话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟然来这么几句打油诗。
好呀,老师的责任就是帮你解决问题,既然想种田,那就分你一块。
这块田位于浙江省温州市苍南县灵溪镇林家铺子村,多边形形状的一块地,原本是linle 的,现在就准备送给你了。不过,任何事情都没有那么简单,你必须首先告诉我这块地到底有多少面积,如果回答正确才能真正得到这块地。
发愁了吧?就是要让你知道,种地也是需要AC知识的!以后还是好好练吧...
 

Input
输入数据包含多个测试实例,每个测试实例占一行,每行的开始是一个整数n(3<=n<=100),它表示多边形的边数(当然也是顶点数),然后是按照逆时针顺序给出的n个顶点的坐标(x1, y1, x2, y2... xn, yn),为了简化问题,这里的所有坐标都用整数表示。
输入数据中所有的整数都在32位整数范围内,n=0表示数据的结束,不做处理。
 

Output
对于每个测试实例,请输出对应的多边形面积,结果精确到小数点后一位小数。
每个实例的输出占一行。
 

Sample Input
  
  
3 0 0 1 0 0 1 4 1 0 0 1 -1 0 0 -1 0
 

Sample Output
  
  
0.5 2.0
#include<stdio.h>
#include<string.h>
#include<math.h>
typedef struct point{
     double x;
     double y;
}p;
int n;
double solve(point a[])
{
      double s=0;
      int i;
          for(i=0;i<n;i++)
        {
            if(i!=n-1)
                s+=a[i].x*a[i+1].y-a[i].y*a[i+1].x;
            else s+=a[n-1].x*a[0].y-a[n-1].y*a[0].x;
        }

      return s;
}
int main()
{
     while(~scanf("%d",&n),n)
     {
           p a[150]={0};
           for(int i=0;i<n;i++)
           {
              scanf("%lf%lf",&a[i].x,&a[i].y);
           }
           printf("%.1lf\n",fabs(solve(a)/2.0));
     }
}

Q - 今年暑假不AC 

http://acm.hdu.edu.cn/showproblem.php?pid=2037

Problem Description
“今年暑假不AC?”
“是的。”
“那你干什么呢?”
“看世界杯呀,笨蛋!”
“@#$%^&*%...”

确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。
作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)
 

Input
输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。
 

Output
对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。
 

Sample Input
  
  
12 1 3 3 4 0 7 3 8 15 19 15 20 10 15 8 18 6 12 5 10 4 14 2 9 0
 

Sample Output
  
  
5
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node{
      int si;
      int fi;
}a[150];
bool cmp(node x,node y)
{
      return x.fi<y.fi;
}
int main()
{
       int n;
       while(~scanf("%d",&n),n)
       {
              int i;
              for(i=0;i<n;i++)
              {
                   scanf("%d%d",&a[i].si,&a[i].fi);
              }
              sort(a,a+n,cmp);
              struct node p=a[0];
              int sum=1;
              for(i=1;i<n;i++)
              {
                   if(p.fi<=a[i].si)
                   {
                        sum++;
                        p=a[i];
                   }
              }
              printf("%d\n",sum);
       }
       return 0;

}

R - 三角形

http://acm.hdu.edu.cn/showproblem.php?pid=2039

Problem Description
给定三条边,请你判断一下能不能组成一个三角形。
 

Input
输入数据第一行包含一个数M,接下有M行,每行一个实例,包含三个正数A,B,C。其中A,B,C <1000;
 

Output
对于每个测试实例,如果三条边长A,B,C能组成三角形的话,输出YES,否则NO。
 

Sample Input
  
  
2 1 2 3 2 2 2
 

Sample Output
  
  
NO YES
#include<stdio.h>
int main()
{
     double a,b,c;
     int n;
     scanf("%d",&n);
     while(n--)
     {
          scanf("%lf%lf%lf",&a,&b,&c);
          if(a+b>c)
          {
              if(b+c>a)
                 {
                    if(a+c>b)
                    {
                        printf("YES\n");
                        continue;
                    }
                    else
                    {
                        printf("NO\n");
                        continue;
                    }

                 }
              else
               {
                 printf("NO\n");
                 continue;
               }
          }
          else
         {
            printf("NO\n");
            continue;
         }
     }
     return 0;
}

S - 亲和数 

http://acm.hdu.edu.cn/showproblem.php?pid=2040

Problem Description

古希腊数学家毕达哥拉斯在自然数研究中发现,220的所有真约数(即不是自身的约数)之和为: 

1+2+4+5+10+11+20+22+44+55+110=284。 

而284的所有真约数为1、2、4、71、 142,加起来恰好为220。人们对这样的数感到很惊奇,并称之为亲和数。一般地讲,如果两个数中任何一个数都是另一个数的真约数之和,则这两个数就是亲和数。 

你的任务就编写一个程序,判断给定的两个数是否是亲和数
 

Input
输入数据第一行包含一个数M,接下有M行,每行一个实例,包含两个整数A,B; 其中 0 <= A,B <= 600000 ;
 

Output
对于每个测试实例,如果A和B是亲和数的话输出YES,否则输出NO。
 

Sample Input
  
  
2 220 284 100 200
 

Sample Output
  
  
YES NO
#include<stdio.h>
typedef long long ll;
int main()
{
       ll a,b;
       int n;
       scanf("%d",&n);
       while(n--)
       {
            scanf("%lld%lld",&a,&b);
            ll sum1=0,sum2=0,i;
            for(i=1;i<a;i++)
            {
                if(a%i==0)
                {
                   sum1+=i;
                }
            }
            for(i=1;i<b;i++)
            {
                if(b%i==0)
                {
                    sum2+=i;
                }
            }
            if(sum1==b&&sum2==a)
            {
                 printf("YES\n");
            }
            else
            {
                  printf("NO\n");
            }
       }
       return 0;

}


  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值