丹青楼
Problem:A
Time Limit:1000ms
Memory Limit:65536K
Description
在NEFU校园内,有一栋丹青楼,总共有17 777 777 777层,编号从- 8 888 888 888 到8 888 888 888。尤其是,这里有0层,即在-1层与1层之间。 有一个观点存在于NEFU学生心中,那就是数字‘8’是幸运数字。而且,如果一个整数里面至少包含一个数字‘8’那么这个整数就是幸运的,即在这楼层考试,你就肯定不会挂科。例如,8,-180,808这些都是幸运数字,42,-10这些不是。 那么,你即将在丹青楼参加一场考试,考场楼层让你选。你现在在a层,你需要找一个最小的正整数b,你往上再走b层就可以到达为幸运数字的楼层,从而确保这场考试不挂。
Input
输入为一个整数,即题干中所描述的a(-10^9<=a<=10^9)
Output
输出只有一行,即所要求的b。
Sample Input
179 -1 18
Sample Output
1 9 10
写一个函数判断各个位
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
bool cal(int x)
{
int tmp=x,len=0;
while(tmp)
{
tmp/=10;
len++;
}
for(int i=0;i<len;i++)
{
int res=x%10;
if(res<0)res=-res;
if(res==8)return false;
x/=10;
}
return true;
}
int main()
{
int x;
while(~scanf("%d",&x))
{
int cnt=1;
x++;
while(cal(x))
{
x++;
cnt++;
}
printf("%d\n",cnt);
}
return 0;
}
数学题
Problem:B
Time Limit:1000ms
Memory Limit:65536K
Description
由于参加数学考试时你没有选对幸运楼层,数学肯定是挂了,现在你开始为开学前补考做准备。 现在你遇到了一个数学题,对于下面的这个方程,你要求出x(0 < x < 10^9)的所有整数解 x=b*S(x)^a+c 其中a,b,c是给定的值,函数S(x)求得是整数x上的所有数字之和。 现在,需要你来解决这道题。
Input
输入只有一行,分别为题干中描述的a,b,c(1<=a<=5, 1<=b<=10000,-10000<=c<=10000)
Output
输出有两行,第一行为n,表示你找到了n组解,第二行为n个整数,即你找到的对于上述方程的n个解,且以升序排列。每个解都严格大于0且小于10^9。
Sample Input
3 2 8 1 2 -18 2 2 -1
Sample Output
3 10 2008 13726 0 4 1 31 337 967
vector不定长数组 STL中的数据结构 自己先学学吧 很方便
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
long long pow(int x,int z)
{
if(z==1)return x;
else if(z==2)return 1L*x*x;
else if(z==3)return 1L*x*x*x;
else if(z==4)return 1L*x*x*x*x;
else return 1L*x*x*x*x*x;
}
int cal(long long x)
{
int sum=0;
while(x)
{
sum+=(x%10);
x/=10;
}
return sum;
}
vector<long long>val;
int main()
{
int a, b,c;
while(~scanf("%d%d%d",&a,&b,&c))
{
val.clear();
for(int i=1;i<=81;i++)
{
long long x=b*pow(i,a)+c;
if(x>1000000000L)break;
if(cal(x)==i) {
val.push_back(x);
}
}
printf("%d\n",val.size());
if(val.size()!=0)
{
printf("%lld",val[0]);
for(int i=1;i<val.size();i++)printf(" %lld",val[i]);
puts("");
}
}
return 0;
}
素数问题
Problem:C
Time Limit:1000ms
Memory Limit:65536K
Description
现在给你一个正整数n(n<=10000),问你有多少组(p1,p2,p3)满足p1<=p2<=p3,p1,p2,p3都是素数,且p1+p2+p3=n
Input
输入只有一行,为n(n<=10000)
Output
输出也只有一行,即所问有多少组(p1,p2,p3)
Sample Input
3 9
Sample Output
0 2
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int num[10000];
bool pri[10009];//质数
int tot=2;
void cal()
{
num[0]=2;
num[1]=3;
memset(pri,0,sizeof(pri));
pri[1]=1;
for(int i=4;i<=10000;i++)
{
int sqr=(int)sqrt(i);
bool exi=1;
for(int j=2;j<=sqr;j++)
{
if(i%j==0)
{
pri[i]=1;
exi=0;
break;
}
}
if(exi)num[tot++]=i;
}
}
int main()
{
cal();
int x;
while(~scanf("%d",&x))
{
int cnt=0;
for(int i=0;i<tot&&num[i]<=x;i++)
for(int j=i;j<tot&&num[i]+num[j]<x;j++)
if(x-num[i]-num[j]>=num[j]&&!pri[x-num[i]-num[j]])
cnt++;
printf("%d\n",cnt);
}
return 0;
预测比赛
Problem:D
Time Limit:1000ms
Memory Limit:65536K
Description
现在有小胡,小孙,小苗三支足球队,他们总共会进行n场足球比赛,现在已经踢完k场比赛。你是一个足球迷,但是你错过了这k场比赛,所以你不知道这k场比赛的输赢。但是你朋友告诉你小胡和小孙的胜场局数差的绝对值为d1,小孙和小苗的胜场局数差的绝对值为d2。 现在请问你,在进行完这n场比赛后,这三支足球队是否能有相同的胜场局数? 由于你朋友不是acmer,对于数据方面不是很严谨, 所以可能给你错误的比分差,这样的话直接认为不能有相同的胜场局数,请参考第5组样例。
Input
输入只有一行,分别是n,k,d1,d2 (1<=n<=10^12 , 0<=k<=n , 0<=d1,d2<=k)
Output
输出也只有一行,如果能有相同的胜场局数,就输出”yes”,否则输出”no”。
Sample Input
3 0 0 0 3 3 0 0 6 4 1 0 6 3 3 0 3 3 3 2
Sample Output
yes yes yes no no
小胡和小孙的胜场局数差的绝对值为d1,小孙和小苗的胜场局数差的绝对值为d一共四种情况
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main()
{
long long int k,n,d1,d2,s,m,h;
int i,ii;
bool result;
while(scanf("%lld%lld%lld%lld",&n,&k,&d1,&d2)!=EOF)
{
result=false;
if(n%3!=0)
goto endd;
s=k-d1-d2;
m=k-d1+2*d2;
h=k+2*d1-d2;
if((s<=n)&&(m<=n)&&(h<=n)&&(s%3==0)&&(m%3==0)&&(h%3==0)&&(m>=0)&&(s>=0)&&(h>=0))
{
result=true;
}
s=k-d1+d2;
m=k-d1-2*d2;
h=k+2*d1+d2;
if((s<=n)&&(m<=n)&&(h<=n)&&(s%3==0)&&(m%3==0)&&(h%3==0)&&(m>=0)&&(s>=0)&&(h>=0))
{
result=true;
}
s=k+d1+d2;
m=k-2*d1+d2;
h=k+d1-2*d2;
if((s<=n)&&(m<=n)&&(h<=n)&&(s%3==0)&&(m%3==0)&&(h%3==0)&&(m>=0)&&(s>=0)&&(h>=0))
{
result=true;
}
s=k+d1-d2;
m=k+d1+2*d2;
h=k-2*d1-d2;
if((s<=n)&&(m<=n)&&(h<=n)&&(s%3==0)&&(m%3==0)&&(h%3==0)&&(m>=0)&&(s>=0)&&(h>=0))
{
result=true;
}
endd:
if(result==false)
printf("no\n");
else if(result==true)
printf("yes\n");
}
return 0;
}
GPA
Problem:E
Time Limit:1000ms
Memory Limit:65536K
Description
我们都知道加权平均成绩是AVERAGE SCORE = ∑(Wi * SCORE[i]) / ∑(Wi) , 1<=i<=N这么算的,那么假如现在每门课的学分都为1,AVERAGE SCORE =∑(SCORE[i]) / N , 1<=i<=N。另外,SCORE[i]在60到100之间。在NEFU,除了加权平均成绩,我们还用绩点,即GPA来评价一个学生,成绩所对应的相应绩点如下: SCORE[i] GPA[i] 85-100 4 80-84 3.5 75-79 3.0 70-74 2.5 60-69 2.0 一个学生的平均学分绩点GPA = ∑(GPA[i]) / N , 1<=i<=N。 现在给你某个学生的平均成绩AVERAGE SCORE和他修的课程总数 N,所以他每门课的分数是不确定的,也就是每门课的绩点是不确定的,那么请你算出他的最大GPA和最小GPA。
Input
输入只有一行,为两个整数,分别是AVERAGE SCORE和N (60 <= AVGSCORE <= 100, 1 <= N <= 10)
Output
输出只有一行,有两个整数,分别为可能的最小GPA和最大GPA(分别保留4位小数)
Sample Input
75 1 75 2 75 3 75 10
Sample Output
3.0000 3.0000 2.7500 3.0000 2.6667 3.1667 2.4000 3.2000
#include<stdio.h>
#include<stdlib.h>
int main()
{
int as,n,s;
double m1,m2;
while(scanf("%d%d",&as,&n)!=-1)
{
double gpa;
m1=2;m2=4;
s=as*n;
for(int a=0;a<=s/85;a++)
for(int b=0;b<=s/80;b++)
for(int c=0;c<=s/75;c++)
for(int d=0;d<=s/70;d++)
for(int e=0;e<=s/60;e++)
if(a+b+c+d+e==n&&a*85+b*80+c*75+d*70+e*60<=s&&
a*100+b*84+c*79+d*74+e*69>=s)
{
gpa=(a*4+b*3.5+c*3.0+d*2.5+e*2.0)/(double)n;
if(gpa>m1) m1=gpa;
if(gpa<m2) m2=gpa;
}
printf("%.4lf %.4lf\n",m2,m1);
}
return 0;
}