周赛反思1

标题:周赛反思 1

一级目录:题目分析

题目:D
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We’re assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + … + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.

The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.

For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
Input
1.00
3.71
0.04
5.19
0.00
Output
3 card(s)
61 card(s)
1 card(s)
273 card(s)在这里插入图片描述
简单题,却写不出来!
看懂了题目,却没完全看懂🤯。
先看看WA代码

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
     float n,sum=0,k;
      int i,j;
    while(scanf("%f",&n)!=EOF){
        if(n==0.00)break;
        if(n>=0.01&&n<=5.20){
            sum=0;
        for(i=1;i<=1000;i++){
            k=(float)1/(i+1);
            sum+=k;
            if(sum>=n&&sum-k<=n)j=i;
        }
        printf("%d card(s)\n",j);
   		 }
    }   
     return 0;
    }

按案例输入,毫无问题,但是当输入***0.5***时,输出却是 ***2card(s)***。
可是按照题目要求,此处应该为 1card(s)
因为 1/2=0.5 i=1;
所以这个程序有弊端。比赛时却花老长时间才看出来。
接下来,解决这个问题
我改动 如下:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
     float n,sum=0,k;
      int i,j;
    while(scanf("%f",&n)!=EOF){
        if(n==0.00)break;
        if(n>=0.01&&n<=5.20){
            sum=0;
        for(i=1;i<=1000;i++){
            k=(float)1/(i+1);
            sum+=k;
            j=i;
            if(sum>=n)break;
            
        }
        printf("%d card(s)\n",j);
    }
    }
        return 0;
    }

输入0.5后,输出为1.
兴高采烈地提交上去后,等来的却是红红的WA😭。
我又测试了以下数值:
0.5 0.83 1.08 1.28
结果也是符合。
我百思不得其解,只好病急乱投医,将float 改成double …
你猜怎么着
竟然AC了。😋
我也不知道为什么,如若君知,请务告知。在线等。
下面是AC代码:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
     double n,sum=0,k;
      int i,j;
    while(scanf("%lf",&n)!=EOF){
        if(n==0.00)break;
        if(n>=0.01&&n<=5.20){
            sum=0;
        for(i=1;i<=1000;i++){
            k=(double)1/(i+1);
            sum+=k;
            j=i;
            if(sum>=n)break;
            
        }
        printf("%d card(s)\n",j);
    }
    }
        return 0;
    }
    

题目:B

From the article Number Theory in the 1994 Microsoft Encarta: “If a, b, c are integers such that a = bc, a is called a multiple of b or of c, and b or c is called a divisor or factor of a. If c is not 1/-1, b is called a proper divisor of a. Even integers, which include 0, are multiples of 2, for example, -4, 0, 2, 10; an odd integer is an integer that is not even, for example, -5, 1, 3, 9. A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors; for example, 6, which equals 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers. A positive number that is not perfect is imperfect and is deficient or abundant according to whether the sum of its positive, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; 12, with proper divisors 1, 2, 3, 4, 6, is abundant.”
Given a number, determine if it is perfect, abundant, or deficient.
Input
A list of N positive integers (none greater than 60,000), with 1 < N < 100. A 0 will mark the end of the list.
Output
The first line of output should read PERFECTION OUTPUT. The next N lines of output should list for each input integer whether it is perfect, deficient, or abundant, as shown in the example below. Format counts: the echoed integers should be right justified within the first 5 spaces of the output line, followed by two blank spaces, followed by the description of the integer. The final line of output should read END OF OUTPUT.
Sample Input
15 28 6 56 60000 22 496 0
Sample Output
PERFECTION OUTPUT
15 DEFICIENT
28 PERFECT
6 PERFECT
56 ABUNDANT
60000 ABUNDANT
22 DEFICIENT
496 PERFECT
END OF OUTPUT

又是一道简单题的变式,可是考试时根本没写🧎🏻。
就讲一下后面补题时,出的错误吧。
思路很简单,求除了自身输入的数的因数,再相加判断。只是输出时应该审清题目:
1️⃣:输出行的前5个空格内右对齐
2️⃣;最后一行应该是输出的末尾//意思换行(?)。
AC代码:

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int n,i,j=0,k;
    cout<<"PERFECTION OUTPUT"<<endl;
    while(scanf("%d",&n)!=EOF){
       
        j=0;
        if(n==0){
            printf("END OF OUTPUT\n");
            break;
        }
        for(i=1;i<n;i++){
            if(n%i==0)j+=i;
            else continue;
        }
        if(j==n)printf("%5d  PERFECT\n",n);
        if(j>n)printf("%5d  ABUNDANT\n",n);
        if(j<n)printf("%5d  DEFICIENT\n",n);
                       
    }
    return 0;
}

//注:当x=1;输出的应是***DEFICIEN***;

题目:C
You have aa coins of value nn and bb coins of value 11. You always pay in exact change, so you want to know if there exist such xx and yy that if you take xx (0 \le x \le a0≤x≤a) coins of value nn and yy (0 \le y \le b0≤y≤b) coins of value 11, then the total value of taken coins will be SS.

You have to answer qq independent test cases.

Input
The first line of the input contains one integer qq (1 \le q \le 10^41≤q≤10
4
) — the number of test cases. Then qq test cases follow.

The only line of the test case contains four integers aa, bb, nn and SS (1 \le a, b, n, S \le 10^91≤a,b,n,S≤10
9
) — the number of coins of value nn, the number of coins of value 11, the value nn and the required total value.

Output
For the ii-th test case print the answer on it — YES (without quotes) if there exist such xx and yy that if you take xx coins of value nn and yy coins of value 11, then the total value of taken coins will be SS, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example
Input
4
1 2 3 4
1 2 3 6
5 2 6 27
3 3 5 18
Output
YES
NO
NO
YES

第一次写这道题时,理解错了题目意思以为是单纯是判断a乘n+bS,运行案例后才发现错误,再仔细地过了几遍题目材料后才搞清题目意思。
x要在a的范围内,y要在b的范围内,而且x乘n+y
S,a,b,n,S.是输入的数值。
大致思路如下:
就是先求出最大个数的a,然后加上b的个数,最后再去判断b的个数是不是满足就ok了。
我刚开始写了一个宕长的代码,超时了
如下:

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int n,a,b,S;
    int m,i,j;
    int value1=0,value2;
    scanf("%d",&m);
    while(m--){
        int flag=0,value1=0,value2=0;
        scanf("%d%d%d%d",&a,&b,&n,&S);
        for(i=1;i<=a;i++){
            value1=i*n;
            if(value1>S&&(i-1)*n<S){
                value1=(i-1)*n;
                break;
            }
        }
        for(j=1;j<=b;j++){
            value2=j;
            if(value2+value1>=S)flag=1;
        }
        if(flag==1)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

太麻烦了,又烂又长。
应该换一种思路,倒推。从结果入手——S。
就是先求出最大个数的a,然后s减去,最后再去判断1的个数是不是满足就ok了。

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int t,a,b,n,s,k,num;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d",&a,&b,&n,&s);
       	 k=s/n;
         num=0;
        if(k<=a)
        {
            num=k;
        }
        else
        {
            num=a;
        }
        int w=s-1*n*num;
        if(b>=w)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

二级目录:总结

本月的第二个周与第三周已经连续两周在周赛上一道题都没有写出来了。
就连很简单的几道题在周赛上也一直未写出来。
本周的几道题是从前写过的题的变式,都非常简单,却花费了大量时间。
究其根本,还是自己未真正理解这个程序是怎么来的,用处是什么,只是单纯的“背下来”再默写重新提交一遍而已,并未真正理解。
对于一些非常简单的题,如D题,好像是写出来了,结果一交是错的。寻找BUG的能力弱,明知程序有错误,却无法找出错误,一直在最开始错误的思路上重复,不知道改变思路。
在细节方面,小错误频出。
在周赛内,也应该保持一颗平常心,不以没做出来而焦虑,保持节奏。还应该集中注意力,不要被外界所打扰。
认真读题仔细一点,不要图快,反而会浪费更多时间。
加强阅读理解能力,不要下次又理解错题意,认真记英语,不能一直依靠翻译器,虽然有时用了翻译器也不知道题目所什么意思。。。
对于每一次重审,应该跳出之前错误的思路,用新的思路审视,不要固于当前方法。
最重要的是,在比赛时一定要保持专注专注专注
多发散思考。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值