A和B做法和官方题解一样

C题我是用背包+map,先把任务按最早開始的时间进行排序,然后去背包,dp[j]表示j时间能得到最大的得分,然后就过了。。

代码:

A:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;int n, b;char str[205];
int ans[205];int get(char c) {if (c >= '0' && c <= '9') return c - '0';return c - 'a' + 10;
}void print(int c) {if (c >= 0 && c <= 9) printf("%d", c);else printf("%c", c + 'a' - 10);
}int main() {while (~scanf("%d%d", &n, &b)) {memset(ans, 0, sizeof(ans));while (n--) {scanf("%s", str);int len = strlen(str);for (int i = len - 1; i >= 0; i--) {ans[len - i - 1] += get(str[i]);}}for (int i = 0; i < 204; i++) {ans[i] %= b;}int i;for (i = 204; i >= 0; i--) {if (ans[i])break;}if (i == -1) i++;for (int j = i; j >= 0; j--)print(ans[j]);printf("\n");}return 0;
}

B:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;typedef long long ll;ll n, p;ll muti(ll a, ll n, ll p) {ll r = 0;while(n){if(n&1){r += a;if(r >= p) r -= p;}n >>= 1;a += a;if(a >= p) a -= p;}return r;
}ll pow_mod(ll x, ll k) {ll ans = 1;x %= p;while (k) {if (k&1) ans = muti(ans, x, p);x = muti(x, x, p);k >>= 1;}return ans;
}int main() {while (~scanf("%I64d%I64d", &n, &p)) {if (n == 1) printf("%I64d\n", n % p);else printf("%I64d\n", ((pow_mod(2LL, n) - 2) % p + p) % p);}return 0;
}

C:

#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;typedef long long ll;
const int N = 35;int n;
ll w;struct Q {int t, v, l, s;void read() {scanf("%d%d%d", &t, &v, &l);s = max(0, l - t);}
} q[N];map<int, ll> dp[2];
map<int, ll>::iterator it;bool cmp(Q a, Q b) {if (a.s == b.s) return a.t < b.t;return a.s < b.s;
}int main() {while (~scanf("%d%I64d", &n, &w)) {ll sum = 0;for (int i = 0; i < n; i++) {q[i].read();sum += q[i].v;}if (sum < w) {printf("zhx is naive!\n");continue;}sort(q, q + n, cmp);int now = 0, pre = 1;dp[now].clear();dp[now][0] = 0;for (int i = 0; i < n; i++) {swap(now, pre);dp[now].clear();for (it = dp[pre].begin(); it != dp[pre].end(); it++) {int pt = it->first;ll pw = it->second;dp[now][pt] = max(dp[now][pt], pw);int ut = max(pt, q[i].s) + q[i].t;dp[now][ut] = max(dp[now][ut], pw + q[i].v);}}for (it = dp[now].begin(); it != dp[now].end(); it++) {if (it->second >= w) {int ans = it->first;printf("%d\n", ans);break;}}}return 0;
}

BestCoder Round #33相关推荐

  1. hdu4585 amp; BestCoder Round #1 项目管理(vector应用)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [ ...

  3. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...

  4. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...

  5. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio&g ...

  6. hdu4932 Miaomiao#39;s Geometry (BestCoder Round #4 枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 Miaomiao's Geometry Time Limit: 2000/1000 MS (Ja ...

  7. HDU 5228 ZCC loves straight flush( BestCoder Round #41)

    题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    ...

  8. BestCoder Round #90 Kblack loves flag

     BestCoder Round #90 Kblack loves flag 问题描述 kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,kblack得到了一个n∗mn*mn∗ ...

  9. HDU 5804 BestCoder Round #86 Price List (水题)

    Price List 题目链接: 点我打开链接 Source BestCoder Round #86  题意:有一个人去 n 间商店购物,在每家商店购买最多一件物品,也可以什么都不买.给你每家商店的物 ...

最新文章

  1. 大图剪切工具,大图分割工具
  2. python求数列的积_python小游戏学习笔记4-2(列表【】,数列矩阵排列)
  3. python语言的变量随时_Python参数注解
  4. IETester - IE5.5、IE6、IE7、IE8、IE9共存
  5. AI算法连载21:统计之概率图模型
  6. WinXP下变量方式表达对应路径说明
  7. 机器学习之PCA原理
  8. 大疆反腐45人被查处 被开除员工喊话CEO汪滔自称“被冤枉”
  9. SpringCloud学习笔记021---SpringBoot修改内部Tomcat默认端口
  10. 【知识笔记】WebForm
  11. 非模块化jar的模块化转换
  12. 硅谷也疯狂 IT互联网进入中美跨境人才抢夺战时代
  13. SAI红绿蓝三原色叠加效果
  14. 彩虹QQ查看对方ip原理
  15. js_ctype linux,linux – 解释export LANG,LC_CTYPE,LC_ALL的效果
  16. 8大排序算法总结-Python
  17. HTML5期末大作业:美妆网页主题网站设计——清新的手工肥皂网站展示(4页)HTML+CSS+JavaScript...
  18. pycharm中出现pytest_pytest文档3-pycharm运行pytest
  19. 2022年最受欢迎的十大狗狗品种排行榜:拉布拉多猎犬第一 | 美通社头条
  20. python怎么加载图片png图片位置_Python添加png图片出现的问题和解决

热门文章

  1. Effective C++ 读后感
  2. [Java]LeetCode138. 复制带随机指针的链表 | Copy List with Random Pointer
  3. 如何获得Windows聚焦壁纸0726
  4. ##6.2 Neutron计算节点-- openstack pike
  5. 自己动手写spring(三) 支持注解方式
  6. php mysqli的乱码设置
  7. 配置Tomcat的server.xml以适应web-content文件系统的位置改变
  8. 报表服务扩展:基于WCF技术的报表服务扩展
  9. 用C#委托实现哨兵和敌人的观察者模式!
  10. 没错,Java 人的下半场才刚开始!