找回密码
 立即注册
查看: 402|回复: 0

DHU数字游戏

[复制链接]
发表于 2022-3-7 09:36 | 显示全部楼层 |阅读模式
问题描述
  栋栋正在和同学们玩一个数字游戏。

游戏的规则是这样的:栋栋和同学们一共n个人围坐在一圈。栋栋首先说出数字1。接下来,坐在栋栋左手边的同学要说下一个数字2。再下面的一个同学要从上一个同学说的数字往下数两个数说出来,也就是说4。下一个同学要往下数三个数,说7。依次类推。

为了使数字不至于太大,栋栋和同学们约定,当在心中数到 k-1 时,下一个数字从0开始数。例如,当k=13时,栋栋和同学们报出的前几个数依次为:
  1, 2, 4, 7, 11, 3, 9, 3, 11, 7。

游戏进行了一会儿,栋栋想知道,到目前为止,他所有说出的数字的总和是多少。
输入格式
  输入的第一行包含三个整数 n,k,T,其中 n 和 k 的意义如上面所述,T 表示到目前为止栋栋一共说出的数字个数。
输出格式
  输出一行,包含一个整数,表示栋栋说出所有数的和。
样例输入
3 13 3
样例输出
17
样例说明
  栋栋说出的数依次为1, 7, 9,和为17。
数据规模和约定
  1 < n,k,T < 1,000,000;


image.png

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;const int INF=0x3f3f3f3f;#define mem(x,y) memset(x,y,sizeof(x))#define SI(x) scanf("%d",&x)#define PI(x) printf("%d",x)#define SD(x,y) scanf("%lf%lf",&x,&y)#define P_ printf(" ")typedef long long LL;int main(){    int n,k,T;    scanf("%d%d%d",&n,&k,&T);    LL ans=0;    LL temp=1,t=n;    for(int i=0;i<T;i++){        ans+=temp;        if(t&1)temp=(1+(t+1)/2*t%k)%k;        else temp=(1+t/2*(t+1)%k)%k;        t=(t+n)%(2*k);        /*for(int j=0;j<n;j++){            t++;            if(t>=k)t%=k;            temp+=t;            if(temp>=k){                temp=temp-k;            }          }*/    }    printf("%lld\n",ans);    return 0;}#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;const int INF=0x3f3f3f3f;#define mem(x,y) memset(x,y,sizeof(x))#define SI(x) scanf("%d",&x)#define PI(x) printf("%d",x)#define SD(x,y) scanf("%lf%lf",&x,&y)#define P_ printf(" ")typedef long long LL;int main(){    int n,k,T;    scanf("%d%d%d",&n,&k,&T);    LL ans=0;    LL temp=1,t=n;    for(int i=0;i<T;i++){        ans+=temp;        if(t&1)temp=(1+(t+1)/2*t%k)%k;        else temp=(1+t/2*(t+1)%k)%k;        t=(t+n)%(2*k);        /*for(int j=0;j<n;j++){            t++;            if(t>=k)t%=k;            temp+=t;            if(temp>=k){                temp=temp-k;            }        }*/    }    printf("%lld\n",ans);    return 0;}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2025-5-10 04:24 , Processed in 0.139965 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表