Codeforces Round #326 div2
Problem_A(588A):
题意:
Duff 很喜欢吃肉, 每天都要吃,然而她又懒得下楼。 可以买很多放在家里慢慢吃。然而肉价每天都在变化,现给定一个n, 表示有多少天,然后第i天吃ai kg的肉, 当天的价格为pi。
问满足Duff的要求, 最少需要多少钱。
思路:
稍稍分析, 可以得知, 应该维护一个最小价格。然后按照最小价格去买那一段区间的肉。
代码:
- #include <cmath>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <ctime>
- #include <set>
- #include <map>
- #include <list>
- #include <stack>
- #include <queue>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <iterator>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define LL long long
- #define INF 0x3f3f3f3f
- #define MOD 1000000007
- #define eps 1e-6
- #define MAXN 1000000
- #define MAXM 100
- #define dd {cout<<"debug"<<endl;}
- #define pa {system("pause");}
- #define p(x) {printf("%d\n", x);}
- #define pd(x) {printf("%.7lf\n", x);}
- #define k(x) {printf("Case %d: ", ++x);}
- #define s(x) {scanf("%d", &x);}
- #define sd(x) {scanf("%lf", &x);}
- #define mes(x, d) {memset(x, d, sizeof(x));}
- #define do(i, x) for(i = 0; i < x; i ++)
- #define dod(i, x, l) for(i = x; i >= l; i --)
- #define doe(i, x) for(i = 1; i <= x; i ++)
- int n;
- int a, p;
- int main()
- {
- scanf("%d", &n);
- int sum = , min_p = INF, num = ;
- for(int i = ; i < n; i ++)
- {
- scanf("%d %d", &a, &p);
- if(p < min_p)
- {
- sum = sum + num * min_p;
- min_p = p;
- num = a;
- }
- else
- num += a;
- }
- if(num) sum = sum + num * min_p;
- printf("%d\n", sum);
- return ;
- }
Problem_B(588B):
题意:
给一个数n, 在它所有的约数里(包括1和它自身), 找到这样一个最大的数:不能被某个数的平方整除。例如:8能被4整除, 而4是2的平方 所以不行。
思路:
任何一个数, 都能将其写成质因子分解的形式,从质因子分解式就能看出一个规律, 如果把所有的质因子全部乘起来恰好是满足题意的最大的数。 如果幂超过1, 则只算一个。
因为再多乘任何一个数, 得到的都会是某个平方的倍数(嗯哼, 你多乘的那个质因子)。 So, 答案就出来了。
由于对称的性质, 10^12, 只需要打10^6的素数表就OK了。
代码:
- #include <cmath>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <ctime>
- #include <set>
- #include <map>
- #include <list>
- #include <stack>
- #include <queue>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <iterator>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define LL long long
- #define INF 0x3f3f3f3f
- #define MOD 1000000007
- #define eps 1e-6
- #define MAXN 10000010
- #define MAXM 1000010
- #define dd {cout<<"debug"<<endl;}
- #define pa {system("pause");}
- #define p(x) {printf("%d\n", x);}
- #define pd(x) {printf("%.7lf\n", x);}
- #define k(x) {printf("Case %d: ", ++x);}
- #define s(x) {scanf("%d", &x);}
- #define sd(x) {scanf("%lf", &x);}
- #define mes(x, d) {memset(x, d, sizeof(x));}
- #define do(i, x) for(i = 0; i < x; i ++)
- #define dod(i, x, l) for(i = x; i >= l; i --)
- #define doe(i, x) for(i = 1; i <= x; i ++)
- LL n;
- LL p[MAXN], cnt = ;
- bool a[MAXN];
- void Prime2()
- {
- memset(a, , sizeof(a));
- int i, j;
- for (i = ; i < MAXN; ++i)
- {
- if (!(a[i])) p[cnt ++] = i;
- for (j = ; (j < cnt && i * p[j] < MAXN); ++j)
- {
- a[i * p[j]] = ;
- if (!(i % p[j])) break;
- }
- }
- }
- LL get_ans(LL x)
- {
- LL ans = ;
- for(int i = ; i < cnt ; i ++)
- {
- if(x == ) return ans;
- if(x % p[i] == )
- {
- x /= p[i];
- ans = ans * p[i];
- while(x % p[i] == )
- x /= p[i];
- }
- }
- return ans * x;
- }
- int main()
- {
- Prime2();
- scanf("%I64d", &n);
- printf("%I64d\n", get_ans(n));
- return ;
- }
Problem_C(587A):
题意:
题意是给一个长度为n的序列, 其代表的含义是第i个表示 重量为2^w[i]的一个物品。
而Duff 每次能举起这样一堆物品:这堆物品的和为2^x。
求举完所有的物品所有的最小次数。
思路:
简单分析后能得到一个结论:两个一样的数能合成一个比它大一的数,so 答案就出来了。 排序后不停的往上合成就行了。
代码:
- #include <cmath>
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <ctime>
- #include <set>
- #include <map>
- #include <list>
- #include <stack>
- #include <queue>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <iterator>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define LL long long
- #define INF 0x3f3f3f3f
- #define MOD 1000000007
- #define eps 1e-6
- #define MAXN 1000100
- #define MAXM 100
- #define dd {cout<<"debug"<<endl;}
- #define pa {system("pause");}
- #define p(x) {printf("%d\n", x);}
- #define pd(x) {printf("%.7lf\n", x);}
- #define k(x) {printf("Case %d: ", ++x);}
- #define s(x) {scanf("%d", &x);}
- #define sd(x) {scanf("%lf", &x);}
- #define mes(x, d) {memset(x, d, sizeof(x));}
- #define do(i, x) for(i = 0; i < x; i ++)
- #define dod(i, x, l) for(i = x; i >= l; i --)
- #define doe(i, x) for(i = 1; i <= x; i ++)
- int n;
- int w[MAXN];
- int main()
- {
- int x, ans = ;
- scanf("%d", &n);
- mes(w, );
- for(int i = ; i < n; i ++)
- {
- scanf("%d", &x);
- w[x] ++;
- }
- for(int i = ; i < MAXN; i ++)
- if(w[i])
- {
- w[i + ] = w[i + ] + w[i] / ;
- if(w[i] % ) ans ++;
- }
- printf("%d\n", ans);
- return ;
- }
Codeforces Round #326 div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- Codeforces Round #326(Div2)
CodeForces 588A 题意:Duff喜欢吃肉,想在接下来的n天,每天都有Ai斤肉吃,但每一天肉的单价Pi不定,肉 可以保存不过期,现已知n天每天肉的斤数Ai,以及单价Pi,为了使每天都 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #326 (Div. 2) D. Duff in Beach dp
D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...
随机推荐
- Android_Handler
xml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...
- Find security bugs学习笔记V1.0
Find security bugs学习笔记V1.0 http://www.docin.com/p-779309481.html
- 分布式 ES 操作流程解析
概念解析 CURD 操作 CURD 操作都是针对具体的某个或某些文档的操作,每个文档的 routing 都是确认的,所以其所在分片也是可以事先确定的.该过程对应 ES 的 Document API. ...
- 目前电脑的硬件尺寸参数,计划弄个小一些的ATX机箱
显卡:讯景R9 370x 尺寸:234×115×39mm 主板:技嘉GA-970A-DS3P 尺寸: 30.5X21.5 cm
- asp发布至IIS
最近做的一个任务是使用asp写的,显示的是数据库的报表,但是将报表当前目录发布至IIS后,发现还是运行不了 Set conn = Server.CreateObject("ADODB.Con ...
- hasLayout与Block formatting contexts的学习(下)
BFC布局规则: 内部的Box会在垂直方向,一个接一个地放置. Box垂直方向的距离由margin决定.属于同一个BFC的两个相邻Box的margin会发生重叠 每个元素的margin box的左边, ...
- OAuth2集成——《跟我学Shiro》
http://jinnianshilongnian.iteye.com/blog/2038646 目前很多开放平台如新浪微博开放平台都在使用提供开放API接口供开发者使用,随之带来了第三方应用要到开放 ...
- JNI的一些使用
1.简介 Java Native Interface(JNI) 有时候我们必须要调用本地代码c/c++来克服java中的内存管理和性能限制.java支持通过Java Native Interface( ...
- hive外部表自动读取文件夹里的数据
我们在创建表的时候可以指定external关键字创建外部表,外部表对应的文件存储在location指定的目录下,向该目录添加新文件的同时,该表也会读取到该文件(当然文件格式必须跟表定义的一致),删除外 ...
- AngularJS的学习网站及相关资源整理
学习angularjs的网站及相关资源的整理,会不断更新. angularJs的官网:https://angularjs.org/ API文档:https://docs.angularjs ...