北林校赛 北林oj 1332 冰尘君与扑克魔术

我并没有去北林校赛,队友回来听他们说了一道题,比较有意思。

http://acm.bjfu.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1332

中心思想,类似背包,每加进来一张 大小为t的 牌,那么所有求值范围内的数量都有 res [ i ]+= res [ i - t ];
只给出打表程序:
#include<stdio.h>
#include<cstring>
#include<string.h>
#define mem(x,y) memset(x,y,sizeof(x))
/*题目描述:一副除了大小鬼不在的完整扑克牌。
给出一个1到55的整数,问有多少种方法凑成这个整数*/

int res[60],a[60];
void get55()
{
    mem(res,0);
    for(int i=0;i<13;i++)
        a[i*4]=a[i*4+1]=a[i*4+2]=a[i*4+3]=i+1;
    for(int k=0;k<52;k++)
    {
        int t=a[k];
        for(int i=55;i>t;i--)
         res[i]+=res[i-t];
        res[t]++;
    }
}
int main()
{
    get55();
    for(int i=1;i<=55;i++)
        printf("%d\n",res[i]);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
循环比日程表是一种常见的算法问题,可以使用递归或迭代的方式来生成日程表。下面是一个使用C++编写的循环比日程表的示例代码: ```cpp #include <iostream> #include <vector> using namespace std; void generateSchedule(int teams) { if (teams % 2 != 0) { teams++; // 如果队伍数为奇数,添加一个虚拟队伍 } int rounds = teams - 1; // 总轮次数 int matches = teams / 2; // 每轮的比场次 vector<vector<int>> schedule(rounds, vector<int>(matches)); // 初始化第一轮的比安排 for (int i = 0; i < matches; i++) { schedule[0][i] = i + 1; } // 生成后续轮次的比安排 for (int round = 1; round < rounds; round++) { for (int match = 0; match < matches; match++) { int team1 = schedule[round - 1][match]; int team2; // 计算每个队伍的对手 if (match == 0) { team2 = teams - 1; } else { team2 = schedule[round - 1][match - 1]; } // 考虑虚拟队伍的情况 if (team1 == teams - 1 || team2 == teams - 1) { team1 = (team1 + 1) % (teams - 1); team2 = (team2 + 1) % (teams - 1); } schedule[round][match] = team2; } } // 打印比日程表 for (int round = 0; round < rounds; round++) { cout << "Round " << round + 1 << ": "; for (int match = 0; match < matches; match++) { cout << schedule[round][match] << " vs " << teams - schedule[round][match] - 1 << " "; } cout << endl; } } int main() { int teams; cout << "Enter the number of teams: "; cin >> teams; generateSchedule(teams); return 0; } ``` 这段代码中,我们首先根据输入的队伍数计算总轮次数和每轮的比场次。然后,使用一个二维向量 `schedule` 来存储比安排。我们从第一轮开始,逐轮生成比对阵,并将结果存储在 `schedule` 中。最后,打印出比日程表。 希望这个示例代码对你有帮助!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值