2025年河南工业大学2025新生周赛(3)
A 直播间红包雨抢券赛
根据规则,若某方领取到陷阱红包则直接判输,因此核心目标是避免领取第 k 个红包,即谁能迫使对方领取第 k 个红包,谁就获胜。这等价于争夺 “领取到第 k-1 个红包” 的控制权 —— 若能确保自己领取到第 k-1 个红包,对方就必然要领取第 k 个红包(陷阱),从而获胜。双方每次可领取 1、2 或 3 个红包,且均采用最优策略。观察可知,无论先手(主播)第一次领取 1、2 还是 3 个红包,后手(观众)都能通过对应领取 3、2 或 1 个红包,使两人一轮共领取 4 个红包。依此策略,每轮领取的红包总数始终保持 4 的倍数,形成 “4 个一组” 的节奏。
因此,若 k-1 是 4 的倍数,则后手(观众)可通过上述策略确保自己领取到第 k-1 个红包,迫使先手领取第 k 个陷阱红包,观众获胜;若 k-1 不是 4 的倍数,则先手(主播)可先领取(k-1)除以 4 的余数个红包,随后沿用 “每轮共领 4 个” 的策略,最终由先手领取第 k-1 个红包,迫使观众领取第 k 个陷阱红包,观众失败。
综上,判断观众能否获胜,只需看 k-1 是否为 4 的倍数。
#include <stdio.h> #include <stdlib.h> int main() { int n,k; scanf("%d %d",&n,&k); k--; if(k%4==0) printf("Got it!"); else printf("Miss."); return 0; }
B 时空快递的 “跨天送达”
从出发时间开始,循环判断并进位,推断出送达时间,注意闰年2月,注意格式。
#include <stdio.h> #include <stdlib.h> int isLeapYear(int year) { return (year%4==0&&year%100!=0)||(year%400==0); } int getDaysInMonth(int year, int month) { if(month==2) return isLeapYear(year) ? 29 : 28; else if(month==4||month==6||month==9||month==11) return 30; else return 31; } int main() { int year, month, day; int hour, minute, second; int t; scanf("%d-%d-%d %d:%d:%d", &year, &month, &day, &hour, &minute, &second); scanf("%d", &t); t+=second; second=t%60; minute+=t/60; hour+=minute/60; minute%=60; day+=hour/24; hour%=24; while(day>getDaysInMonth(year, month)) { day-=getDaysInMonth(year, month); month++; if (month>12) { month = 1; year++; } } printf("%04d-%02d-%02d %02d:%02d:%02d\n", year, month, day, hour, minute, second); return 0; }
C 双 11 红包大派送
由于最大红包与最小红包的金额差不超过 1,故输出最多有2个不同的数,可以先求平均值(向下取整),再将多余的金额以每个红包一元分配。
#include <stdio.h> #include <stdlib.h> int main() { int m,k; scanf("%d %d",&m,&k); int cur=m/k; m%=k; for(int i=1;i<=k;i++) { if(i>k-m) printf("%d",cur+1); else printf("%d",cur); if(i<k) printf(" "); } return 0; }
D 银行账单的数字美化
注意到数据范围不大,最多可添加两个“,”,可以直接将原数据以1000为基准拆成三部分,判断最高位,并添加“,”。
#include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d",&n); int a=0,b=0,c=0,f=1; if(n<0) {f=-1;n=-n;} c=n%1000; n/=1000; if(n>0) {b=n%1000;n/=1000;} if(n>0) a=n; if(a!=0) { printf("%d,%03d,%03d",a*f,b,c); } else if(b!=0) { printf("%d,%03d",b*f,c); } else { printf("%d",c*f); } return 0; }
E 数字躲猫猫
注意a,b大小不确定,所以要先判断谁在前,然后循环把不带3的数字相加,注意每次相加都要取模。
#include <stdio.h> #include <stdlib.h> const int mod=1e9+7; int main() { int a,b; scanf("%d %d",&a,&b); if(a>=b) { int t; t=a; a=b; b=t; } int ans=0; for(int i=a;i<=b;i++) { int x=i,f=1; while(x) { int y=x%10; if(y==3) {f=0;break;} x/=10; } if(f) ans=(ans+i)%mod; } printf("%d",ans); return 0; }
F 机器人的寻宝路径
注意连续两次移动方向相同,第二次移动距离翻倍。
#include <stdio.h> #include <stdlib.h> int main() { int x=0,y=0,p=0; char pre='\0'; char c; while((c=getchar())!='\n') { if(c==pre) p++; else p=0; int d=1<<p; switch(c) { case 'U': y+=d;break; case 'D': y-=d;break; case 'L': x-=d;break; case 'R': x+=d;break; default: break; } pre=c; } printf("%d %d\n",x,y); return 0; }
G 密码锁的旋转密码
循环判断每一位,取操作最小值累加。
#include <stdio.h> #include <stdlib.h> int main() { int a; scanf("%d",&a); int ans=0; while(a) { int b=a%10; if(b<10-b) ans+=b; else ans+=10-b; a/=10; } printf("%d",ans); return 0; }
H 魔法水晶的三角形测试
根据所给边判断是否能构成的三角形,如果可以构成三角形,求三角形类型并求面积。
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int a,b,c; scanf("%d %d %d",&a,&b,&c); if(a+b>c&&b+c>a&&a+c>b) { if(a==b&&b==c) printf("Perfect equilateral crystal!!!"); else { int f1=0,f2=0; if(a==b||a==c||b==c) f1=1; if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a) f2=1; if(f1+f2==2) printf("Isosceles right-angle crystal!!"); else if(f1==1) printf("Isosceles crystal!"); else if(f2==1) printf("Right-angle crystal!"); else printf("Common triangular crystal."); } printf("\n"); double p=(a+b+c)/2.0; double ans=sqrt(p*(p-a)*(p-b)*(p-c)); printf("%.2lf",ans); } else printf("It cannot form an energy triangle."); return 0; }
I 日历格式化输出
注意日期起始位置,每个日期占两格,日期与日期之间有空格。
#include <stdio.h> #include <stdlib.h> int main() { int w,d; scanf("%d %d",&w,&d); printf("日 一 二 三 四 五 六\n"); int p=(w+d+6)/7,id=1,f=0; for(int i=0;i<p;i++) { for(int j=0;j<7;j++) { if(i==0&&j<w) printf(" "); else {printf("%2d",id);id++;} if(id>d) {f=1;break;} if(j<6) printf(" "); } if(f==1) break; printf("\n"); } return 0; }
J 魔法天平的反向称重
注意0的位置。
#include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d",&n); int a=0,b=0,c=0; a=n%10;//n的个位 n/=10; b=n%10;//n的十位 n/=10; c=n;//n的百位 printf("%d%d%d",a,b,c); return 0; }

浙公网安备 33010602011771号