纪念SlingShot

很多时候题目里面没有给你n的范围,所以把所有的情况都列出,没有列全的话也会出现time limit 的错误!!!

及时给了不明确,也要列出来

题意:f(0)=1,f(1)=3,f(2)=5,f(n)=3f(n-1)+2f(n-2)+5f(n-3)。求s(n)=(f(0)+f(1)……+f(n))%2009。

思路:S(n)=S(n-1)+F(n)=S(n-1)+3F(n-1)+2F(n-2)+7F(n-3),因此构造矩阵:

 


G - 纪念S lingShot
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

已知 F(n)=3 * F(n-1)+2 * F(n-2)+7 * F(n-3),n>=3,其中F(0)=1,F(1)=3,F(2)=5,对于给定的每个n,输出F(0)+ F(1)+ …… + F(n) mod 2009。

Input

第一行是一整数m,代表总共有m个cases。

Output

对于每个case,输出一行。格式见样例,冒号后有一个空格。

Sample Input

2
3
6

Sample Output

Case 1: 37
Case 2: 313


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <cstdio>
#include <cstring>
#define mod  2009
using namespace std;

struct matrix
{
    int ma[5][5];
};
matrix mult(matrix a,matrix b)
{
    matrix ans;
    memset(ans.ma,0,sizeof(ans.ma));
    for(int i=1;i<=4;i++)
    {
        for(int j=1;j<=4;j++)
        {
            for(int k=1;k<=4;k++)
            {
                ans.ma[i][j]+=(a.ma[i][k]*b.ma[k][j])%mod;
            }
            ans.ma[i][j]%=mod;
        }
    }
    return ans;
}

matrix pow(matrix x,int n)
{
    matrix ans;
    memset(ans.ma,0,sizeof(ans.ma));
    for(int i=1;i<=4;i++)
    {
        ans.ma[i][i]=1;
    }
    while(n)
    {
        if(n&1)
        {
            ans=mult(ans,x);
        }
        x=mult(x,x);
        n>>=1;
    }
    return ans;
}

int main()
{
    int n;
    int t;
    scanf("%d",&t);
    for(int cou=1;cou<=t;cou++)
    {
        scanf("%d",&n);
        if(n==1)
        {
            printf("Case %d: 4\n",cou);
             continue;
        }
        else if(n==2)
        {
            printf("Case %d: 9\n",cou);
            continue;
        }
        else if(n==0)
        {
            printf("Case %d: 1\n",cou);
            continue;
        }
        matrix x;
        memset(x.ma,0,sizeof(x.ma));
        x.ma[1][1]=1,x.ma[1][2]=3,x.ma[1][3]=2,x.ma[1][4]=7;
        x.ma[2][1]=0,x.ma[2][2]=3,x.ma[2][3]=2,x.ma[2][4]=7;
        x.ma[3][1]=0,x.ma[3][2]=1,x.ma[3][3]=0,x.ma[3][4]=0;
        x.ma[4][1]=0,x.ma[4][2]=0,x.ma[4][3]=1,x.ma[4][4]=0;
        x=pow(x,n-2);
        int sum=(x.ma[1][2]*5)%mod+(x.ma[1][3]*3)%mod+(x.ma[1][4]*1)%mod+(x.ma[1][1]*9)%mod;
        printf("Case %d: %d\n",cou,sum%mod);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单版的愤怒的小鸟游戏。 首先,需要安装 Pygame 库。可以通过以下命令在终端中安装: ```python pip install pygame ``` 然后,创建一个名为 "angry_birds.py" 的 Python 文件,输入以下代码: ```python import pygame import random # 初始化 Pygame pygame.init() # 游戏窗口大小 WINDOW_WIDTH = 800 WINDOW_HEIGHT = 600 # 颜色定义 WHITE = (255, 255, 255) BLACK = (0, 0, 0) GREEN = (0, 255, 0) # 创建游戏窗口 screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) pygame.display.set_caption("Angry Birds") # 加载小鸟图片 bird_image = pygame.image.load("bird.png") bird_rect = bird_image.get_rect() bird_x = 100 bird_y = 450 # 加载猪图片 pig_image = pygame.image.load("pig.png") pig_rect = pig_image.get_rect() pig_x = 600 pig_y = 450 # 加载弹弓图片 slingshot_image = pygame.image.load("slingshot.png") slingshot_rect = slingshot_image.get_rect() slingshot_x = 80 slingshot_y = 430 # 初始化速度和加速度 velocity = 0 acceleration = 0.1 # 初始化是否发射小鸟的标志位 fire_bird = False # 游戏主循环 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN: if not fire_bird: # 计算小鸟发射的速度和角度 dx = bird_x - slingshot_x dy = bird_y - slingshot_y angle = -1 * math.atan2(dy, dx) velocity = math.sqrt(dx ** 2 + dy ** 2) / 20 fire_bird = True # 填充背景颜色 screen.fill(WHITE) # 画弹弓 screen.blit(slingshot_image, (slingshot_x, slingshot_y)) if not fire_bird: # 画小鸟 screen.blit(bird_image, (bird_x, bird_y)) else: # 计算小鸟的位置 bird_x += velocity * math.cos(angle) bird_y -= velocity * math.sin(angle) - 0.5 * acceleration * (velocity ** 2) velocity -= acceleration # 画小鸟 screen.blit(bird_image, (bird_x, bird_y)) # 判断小鸟是否与猪碰撞 if bird_rect.colliderect(pig_rect): print("You win!") running = False # 判断小鸟是否飞出屏幕 if bird_x < -50 or bird_x > WINDOW_WIDTH + 50 or bird_y > WINDOW_HEIGHT + 50: print("Game over!") running = False # 画猪 screen.blit(pig_image, (pig_x, pig_y)) # 更新屏幕 pygame.display.update() # 退出 Pygame pygame.quit() ``` 这个游戏中,你需要控制弹弓发射小鸟,使其击中右侧的猪。具体操作为:按住鼠标左键拖动弹弓,松开鼠标左键发射小鸟。 在运行游戏之前,需要准备好 "bird.png"、"pig.png" 和 "slingshot.png" 这三个图片文件,并与 Python 文件保存在同一个目录下。可以自己画或者从网络上下载。 运行游戏时,可以在终端中输入以下命令: ```python python angry_birds.py ``` 希望这个简单版的愤怒的小鸟游戏对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值