Codeforces Round #215 (Div. 2) 解题报告
昨天第一题竟然还错了。。。真是忧伤。现在改过来了
Problem A Sereja and Coat Rack
一共有n个房间第i个能赚ai的钱不够一个房间陪d钱,算最后的赚了多少。
贪心思想赚的少的先来。
1 #include <iostream> 2 #include <cstdio> 3 #include <string.h> 4 #include <algorithm> 5 #define INF 0x7fffffff 6 7 using namespace std; 8 bool cmp(int a, int b){return a>b;} 9 int main() 10 { 11 // freopen("in.txt", "r", stdin); 12 13 int n, d, a[111], m; 14 while(scanf("%d%d", &n, &d)!=EOF){ 15 for(int i=0; i<n; i++){ 16 scanf("%d", &a[i]); 17 } 18 scanf("%d", &m); 19 int ans = 0; 20 sort(a, a+n); 21 for(int i=0; i<min(m,n); i++){ 22 ans+=a[i]; 23 } 24 ans-=d*(m>n?(m-n):0); 25 cout << ans << endl; 26 } 27 return 0; 28 }
View Code
Problem B Sereja and Suffixes
统计第i个后有多少个不同的数,开局初始化一下即可。然后每次查询。
1 #include <iostream> 2 #include <cstdio> 3 #include <string.h> 4 #include <algorithm> 5 #define INF 0x7fffffff 6 7 using namespace std; 8 int tag[100100], dp[100100], a[100100]; 9 10 int main() 11 { 12 // freopen("in.txt", "r", stdin); 13 int n, m; 14 while(scanf("%d%d", &n, &m)!=EOF){ 15 memset(tag, 0, sizeof tag); 16 memset(dp, 0, sizeof dp); 17 for(int i=0; i<n; i++){ 18 scanf("%d", &a[i]); 19 } 20 for(int i=n-1; i>=0; i--){ 21 if(tag[a[i]]==0){ 22 tag[a[i]] = 1; 23 dp[i] = dp[i+1]+1; 24 }else dp[i] = dp[i+1]; 25 } 26 for(int i=0; i<m; i++){ 27 int temp; 28 scanf("%d", &temp); 29 cout << dp[temp-1] << endl; 30 } 31 } 32 return 0; 33 }
View Code
Problem C Sereja and Algorithm
找规律题,想了半天。最终结论很简单只要满足abs(a-b)>=2 || abs(b-c)>=2 || abs(c-a)>=2返回YES否则。
1 #include <iostream> 2 #include <cstdio> 3 #include <string.h> 4 #include <algorithm> 5 #define INF 0x7fffffff 6 7 using namespace std; 8 9 int dp[100100][5]; 10 char str[100100]; 11 12 bool Judge(int a, int b, int c){ 13 if(a==0 || b==0 || c==0) return false; 14 if(abs(a-b)>=2 || abs(b-c)>=2 || abs(c-a)>=2)return false; 15 return true; 16 } 17 18 int main() 19 { 20 // freopen("in.txt", "r", stdin); 21 while(cin >> str+1) 22 { 23 int len = strlen(str+1); 24 for(int i=1; i<=len; i++){ 25 dp[i][0] = dp[i-1][0]; 26 dp[i][1] = dp[i-1][1]; 27 dp[i][2] = dp[i-1][2]; 28 dp[i][str[i]-'x'] ++; 29 } 30 int q, l, r; 31 scanf("%d", &q); 32 for(int i=0; i<q; i++){ 33 scanf("%d%d", &l, &r); 34 int tx = dp[r][0]-dp[l-1][0], ty = dp[r][1]-dp[l-1][1], tz = dp[r][2]-dp[l-1][2]; 35 if(r-l<2)printf("YES\n"); 36 else if(Judge(tx,ty,tz))printf("YES\n"); 37 else printf("NO\n"); 38 } 39 } 40 return 0; 41 }
View Code
转载于:https://www.cnblogs.com/shu-xiaohao/p/3444737.html
Codeforces Round #215 (Div. 2) 解题报告相关推荐
- CodeCraft-19 and Codeforces Round #537 (Div. 2)解题报告
Codeforces Round #537 (Div. 2) 题解报告 A. Superhero Transformation 题意 问能否通过把辅音字母换成另一个辅音字母,元音字母换成另一个元音字母 ...
- Codeforces Round #702 (Div. 3)解题报告
Codeforces Round #702 (Div. 3) 全部题解 读错题意,写了半天真是心态爆炸,总的来看这次题目不难的. A. Dense Array http://codeforces.co ...
- Codeforces Round #264 (Div. 2) 解题报告
Source: http://codeforces.com/contest/463 打得比较差..第三题想写nlgn的,结果调了很久又wa,以为写挫,过了很久发现做法有问题..最后两题惨淡收场.第四 ...
- Codeforces Round #219 (Div. 2) 解题报告
Problem A Collecting Beats is Fun 题意:就是音乐游戏在4*4的网上一些格子需要在固定的时间点,告诉你一只手同一时间能点几个.问你能不能通关(就是一个不丢) 思路:水题 ...
- Codeforces Round #535 (Div. 3) 解题报告
CF1108A. Two distinct points 做法:模拟 如果两者左端点重合就第二条的左端点++就好,然后输出左端点 #include <bits/stdc++.h> usin ...
- Codeforces Round #215 (Div. 2) D. Sereja ans Anagrams
http://codeforces.com/contest/368/problem/D 题意:有a.b两个数组,a数组有n个数,b数组有m个数,现在给出一个p,要你找出所有的位置q,使得位置q q+ ...
- Codeforces Round #578 (Div. 2) 题解报告
A. Hotelier sb模拟,直接按题意模拟就可以了. B. Block Adventure Gildong is playing a video game called Block Advent ...
- BestCoder Round #77 (div.2)解题报告
昨晚和Yveh合作的成果-- T1 传送门 题意:给一个正整数集合,求集合中各个子集里各元素的总异或 思路:对于一个数x对自己异或的结果,异或偶数次是x,奇数次为0,而且一个集合的非空子集数目为2n− ...
- Codeforces Round #700 (Div. 2)A~D2解题报告
Codeforces Round #700 (Div. 2)A~D2解题报告 A Yet Another String Game 原题链接 http://codeforces.com/contest/ ...
- Codeforces Round #693 (Div. 3)A~G解题报告
Codeforces Round #693 (Div. 3)A~G解题报告 A Cards for Friends 原题信息 http://codeforces.com/contest/1472/pr ...
最新文章
- 机器大神 Michael Jordan 教授主题演讲:机器学习——创新视角,直面挑战》
- python哪里下载import包-python 如何找到import的包
- 将Android实例导入project
- pyinstaller打包执行exe出现“ModuleNotFoundError: No module named ‘scipy.spatial.transform._rotation_group”
- eclipse idea对比_Idea必须配置的环境变量(自己总结)
- 【高并发】JUC中等待多线程完成的工具类CountDownLatch
- Spring框架----自动按照类型注入的Autowired注解
- 官宣!vue.ant.design 低调上线
- HDU 1568 Fibonacci ★(取科学计数法)
- 矢量网络分析仪的基本原理
- 【启动程序是无法加载 libnsl.so.1】
- List接口(ArrayList集合和LinkedList集合)
- Bytom Dapp 开发笔记(二):开发流程
- 51单片机实战之电子时钟
- PHP版本升级了旧代码怎么办?编程语言PHP还有未来吗?[图]
- Internal error: : 8 [#1] PREEMPT SMP ARM,vmlinux反汇编命令调试查找错误的步骤
- 免费App开发解决方案 一键生成App
- (转)iOS6和Xcode4.5初体验-图多杀猫
- 五、Oracle19c下载、安装和验证(适用于Windows系统)
- 16进制加法 keil,16进制加法