2017年浙江理工大学新生赛

没有优化,代码写的还丑,可以说是因为原汁原味吗(ಥ_ಥ)  

Problem A: b^3 - a^3 = c

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 980   Solved: 42

Description

给出一个c, 问是否存在正整数解a, b, 使得b^3 - a^3 = c成立。

Input

有多组测试(组数<=1000),每组给出 c (1<=c<=1e9)

Output

输出一对解"a b"(a<b), 如果有多组合法解,请输出 a 最小的一对解,如果无解的话请输出"-1".

Sample Input

7
11

Sample Output

1 2
-1

代码:

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main(){
    int i,c,a,b;
    while(~scanf("%d",&c)){
        b=1;
        a=1;
        long long TS=b*b*b-a*a*a;
        int flag=0;
        while(TS!=c){
            if(TS>c)a++;
            else b++;
            TS=b*b*b-a*a*a;
            if(TS>c&&b-a==1){
                flag=1;
                break;
            }
        }
        if(flag)printf("-1\n");
        else printf("%d %d\n",a,b);
    }
    return 0;
}

Problem E: 情人节的阻击

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 379   Solved: 16

Description

情人节又快到了,每到这个时候总是 FFF 团最忙碌的时候,他们为了让社会更加和谐,致力于降低社会的狗粮度。
在一个 n*m 影院中,有 x 个男生和 y 个女生,保证 x + y = n * m, 如果有男女相邻或者前后而坐,狗粮度就会增加1,
现在他们已经黑入了影院的订票系统,想请你重新设置每个人的位置,使得影院的狗粮度最低。

Input

多组测试。每组输入形如:
n m x y
 
1<=n, m<=200

Output

每组输出形如:
ans
 

Sample Input

2 2 1 3
4 4 3 13

Sample Output

2
4

贪心策略(这算贪心?):找到男女少的一方设为X,将X尽量朝正方形形状排位置,如果最后矩形的短边大于电影院矩形短边的一半(省去小数部分),那么按照向下填充方法排位置,否则输出a+b。

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main(){
    int n,m,x,y,swa;
    while(~scanf("%d%d%d%d",&n,&m,&x,&y)){
        int ans1=0;
        if(n>m){
            swa=n;
            n=m;
            m=swa;
        }
        if(x>y){
            swa=x;
            x=y;
            y=swa;
        }
        if(x%n==0)ans1=n;
        else if(x/n==0)ans1=x+1;
        else ans1=n+1;
        if(x==0)ans1=0;

        int ans2,a=1,b=1;
        while(a*b<x){
            if(a>b)b++;
            else a++;
        }
        if(b>n/2){
            printf("%d\n",ans1);
            continue;
        }
        ans2=a+b;
        printf("%d\n",ans2);
    }
    return 0;
}

Problem H: magic number

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 357   Solved: 30

Description

如果一个数和它十进制下各个位上数字的和的差小于 S, 那么这个数就是magic number.
现在要求你算出在[l, r]区间内的magic number数量。

Input

多组测试数据(组数<=1000)。
每组输入形如:
l r S
 
1<=l,r,S<=1e9,
 

Output

对于每个询问请输出对应的答案。

Sample Input

100 100 3
100 1000 999
111 2111 233

Sample Output

0
900
129

思路:因为S小于1e9,所以最大符合条件应该略大于(s+9*9),而[L,S]范围内应该全部满足,所以从[S+1,S+200]遍历再加上S-L+1。

代码:

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int f(int n){
    int ans=0;
    while(n){
        ans=ans+n%10;
        n/=10;
    }
    return ans;
}

int main(){
    int l,r,s,swa;
    while(~scanf("%d%d%d",&l,&r,&s)){
        if(l>r){
            swa=l;
            l=r;
            r=swa;
        }
        if(s>=r){
            printf("%d\n",r-l+1);
            continue;
        }
        int ans=0,maxn=s+200,i;
        if(s>l){
            ans=s-l+1;
            l=s+1;
        }
        if(r<maxn)maxn=r;
        for(i=l;i<=maxn;i++)
            if(i-f(i)<s)ans++;
        printf("%d\n",ans);
    }
    return 0;
}

Problem I: 科学计数法

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 528   Solved: 52

Description

科学计数法是将一个数字表示成 a×10的n次方的形式.其中1≤|a|<10,n为整数。
我们给你一个数x, 请把它用科学计数法表示出来,并保留 k 位有效数字。
有效数字是指在一个数中,从该数的第一个非零数字起,直到末尾数字止的数字称为有效数字,如0.618的有效数字有三个,分别是6,1,8。(不用考虑四舍五入)

Input

多组测试数据(组数<=100)。
每组输入形如:
x k
 
0<x<10^120, 0<k<20, 注意读入的数字可能会有前置0。
 

Output

请输出对应的科学计数后的数。

Sample Input

1030 3
1000 2
0.0032 3

Sample Output

1.03e3
1.0e3
3.20e-3


应该是模拟题

代码:

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

char s[150];

int main(){
    int y;
    while(~scanf("%s%d",&s,&y)){
        int c=0,i=0,index=0,dian,len=strlen(s);
        while(s[i]!='.'&&i<len)i++;
        dian=i;
        while(s[index]=='0'||s[index]=='.'){
            index++;
        }

        if(dian>index)c=dian-index-1;
        else c=dian-index;

        printf("%c",s[index]);
        if(y>1)printf(".");
        for(i=1;i<y;i++){
            index++;
            if(s[index]=='.'){
                y++;
                continue;
            }
            if(s[index]=='\0')printf("0");
            else printf("%c",s[index]);
        }
        printf("e%d\n",c);
        memset(s,0,sizeof(s));
    }
    return 0;
}

Problem J: 我好方

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 394   Solved: 292

Description

现在有3个图形,分别是三角形,圆和正方形,已知三角形的边长为a, 圆的半径为b, 正方形的边长为c。
请问哪个图形的面积最大呢 ?
其中正三角形的面积公式为:sqrt(3)/4 * a * a
圆周率 pi = acos(-1.0)

Input

多组测试数据(组数<=100)。
每组输入形如:
a b c
 
a,b,c为正整数,0<a,b,c<100,数据保证存在一个最大的面积。

Output

对于每组数据输出对应的答案:
如果答案是三角形,请输出 triangle;
如果是圆,请输出 circle;
如果是正方形,请输出 square。

Sample Input

11 2 3
5 2 4
5 3 4

Sample Output

triangle
square
circle

代码:

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main(){
    double a,b,c,pi=acos(-1.0);
    while(~scanf("%lf%lf%lf",&a,&b,&c)){
        a=sqrt(3)/4*a*a;
        b=pi*b*b;
        c=c*c;
        if(c>b&&c>a)printf("square\n");
        if(b>c&&b>a)printf("circle\n");
        if(a>b&&a>c)printf("triangle\n");
    }
    return 0;
}

Problem K: 不要方

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 499   Solved: 190

Description

现在有两个矩形,请算出它们公共面积的大小。

Input

多组测试数据。
每组输入形如:
x1 y1 x2 y2
x3 y3 x4 y4
 
(x1,y1)为第一个矩形的左上角的坐标,(x2,y2)位第一个矩形右下角的坐标。
(x3,y3)为第二个矩形的左上角的坐标,(x4,y4)位第二个矩形右下角的坐标。
所有数据的绝对值小于等于100,且均是整数。

Output

请输出对应的答案。

Sample Input

1 4 2 1
0 3 3 2
0 2 1 1
3 4 4 3
0 2 3 1
2 3 4 0

Sample Output

1
0
1

代码:

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int main(){
    int x1,x2,x3,x4,y1,y2,y3,y4,x,y,xmin,ymin,xmax,ymax;
    while(~scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)){
        if(x2<=x3||y2>=y3||x1>=x4||y1<=y4){
            printf("0\n");
            continue;
        }
        if(x1>x3)xmin=x1;
        else xmin=x3;
        if(x2>x4)xmax=x4;
        else xmax=x2;
        x=xmax-xmin;

        if(y1>y3)ymax=y3;
        else ymax=y1;
        if(y2>y4)ymin=y2;
        else ymin=y4;
        y=ymax-ymin;
        x=x*y;
        if(x<0)x=0;
        printf("%d\n",x);
    }
    return 0;
}

Problem L: 丢手绢

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 301   Solved: 42

Description

丢手绢,又叫丢手帕,我国传统的民间儿童游戏。开始前,准备几块手绢,然后大家推选一个丢手绢的人,其余的人围成一个大圆圈蹲下。
游戏开始,被推选为丢手绢的人沿着圆圈外行走。丢手绢的人要不知不觉地将手绢丢在其中一人的身后。被丢了手绢的人要迅速发现自己
身后的手绢,然后迅速起身追逐丢手绢的人,丢手绢的人沿着圆圈奔跑,跑到被丢手绢人的位置时蹲下,如被抓住,则要表演一个节目,
可表演跳舞、歌谣、讲故事等。
Lyf老师碰到一个难题:现在有n个学生围成一圈丢手绢,他们等间距的分布在圆周上,圆的 周长为1000,现在有1个学生出局,剩下的人
要移动位置重新等间距分布,问他们最少需要移动多少距离。Lyf老师脑子有点糊涂,现在这个难题交给你了。

Input

多组测试,每组输入n,1<=n<=1000000000。

Output

对于每组输入,四舍五入输出最少移动距离。

Sample Input

2
3
5

Sample Output

0
167
200

思路:有公式法,但是比赛时想着直接模拟打表(擦掉,超时了才想的打表),500是极限不要问我为什么,慢慢试的 (ಥ_ಥ)  

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

int v[1000];

int main(){
    int n,i;
    for(i=3;i<=500;i++){
        double old=1000./i,ne=1000./(i-1),fir=(2*old-ne)/2;
        int cnt=(i-1)/2,j;
        double sum=fir,last=fir,next;
        for(j=2;j<=cnt;j++){
            next=last+old-ne;
            sum+=next;
            last=next;
        }
        v[i]=2*sum+0.5;
    }
    while(~scanf("%d",&n)){
        if(n>500){
            printf("250\n");
            continue;
        }
        printf("%d\n",v[n]);
    }
    return 0;
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值