Sicily 2014年每周一赛第一场
来源:互联网 发布:电脑性能测试软件 编辑:程序博客网 时间:2024/05/17 07:46
比较苦逼、爆0了、、总结一下吧、
The first and only line of input contains two positive integers, N and M (1 ≤ N, M ≤ 100), the number of sausages and tasters, respectively.
The first and only line of output must contain the required minimum number of cuts.
样例1:2 6样例2:3 4样例3:6 2
样例1:4样例2:3样例3:0
题意就是给你n个香肠,让你平均的分给m个人。问你最少要切几刀? 题目很水!最近做数学题目做的多了。
以为推一个公式呢。其实不是,就是用一个循环无限分的情况!
#include<stdio.h>int main(){ int N, M; while(~scanf("%d%d",&N,&M)) { int ans = 0; while(N % M != 0) { if(N > M) N = N % M; int s = M%N == 0 ? M / N -1 : M / N; M = M % N; ans = ans + s * N; if(M == 0) break; } printf("%d\n",ans); }}
我的错的推公式的代码:
#include <cstdio>int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { if(n==0||m==0) { printf("0\n");continue; } int ans=0; if(n<m) { if(m%n==0) ans=(m/n-1)*n; else { ans=n*(m/n)+n%(m%n); } } else { if(n%m==0) ans=0; else { n=n%m; if(m%n==0) ans=(m/n-1)*n; else { ans=n*(m/n)+n%(m%n); } } } printf("%d\n",ans); } return 0;}
下面做的c题。感觉是一道贪心题目,但是数据很大。超时了。想不到用什么数据结构优化。
10359. Valuable Jewellery
Constraints
Time Limit: 2 secs, Memory Limit: 256 MB
Description
The difficult economic situation in the country and reductions in government agricultural subsidy funding
have caused Mirko to change his career again, this time to a thief. His first professional endeavour is a
jewellery store heist.
The store contains N pieces of jewellery, and each piece has some mass Mi and value Vi . Mirko has K bags
to store his loot, and each bag can hold some maximum mass Ci . He plans to store all his loot in these bags,
but at most one jewellery piece in each bag, in order to reduce the likelihood of damage during the escape.
Find the maximum total jewellery value that Mirko can “liberate”.
Input
The first line of input contains two numbers, N and K (1 ≤ N, K ≤ 300 000).
Each of the following N lines contains a pair of numbers, Mi and Vi (1 ≤ Mi , Vi ≤ 1 000 000).
Each of the following K lines contains a number, Ci (1 ≤ Ci ≤ 100 000 000).
All numbers in the input are positive integers.
Output
The first and only line of output must contain the maximum possible total jewellery value.
Sample Input
样例1:2 15 10100 10011样例2:3 21 655 232 99102
Sample Output
样例1:10样例2:164
Hint
Clarification of the second example: Mirko stores the first piece of jewellery into the second bag and
the third piece into the first bag.
题意很好懂,给出n个珠宝的价格和重量。和k个能装t重量的袋子。条件是一个袋子只能装一个珠宝。问怎样装使得价值最大。想到的就是按价值从大到小排序,价值相同的按重量从大到小排序,然后袋子能装的重量从小到大排序,然后依次选能够装进去的,标记。最后算出ans。
但是超时了。求大神指点。
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;struct Node{ int wi,vi; int ok;};Node a[303000];int bag[303000];int comp(Node x,Node y){ if(x.vi!=y.vi) return x.vi>y.vi; if(x.wi!=y.wi) return x.wi>y.wi;}int main(){ int n,k; while(~scanf("%d%d",&n,&k)) { for(int i=0;i<n;i++) { scanf("%d%d",&a[i].wi,&a[i].vi); a[i].ok=0; } for(int i=0;i<k;i++) scanf("%d",&bag[i]); sort(bag,bag+k); sort(a,a+n,comp); int ans=0; for(int i=0;i<k;i++) { for(int j=0;j<n;j++) { if(bag[i]>=a[j].wi&&a[j].ok==0) { ans+=a[j].vi;a[j].ok=1; break; } } } printf("%d\n",ans); } return 0;}
- Sicily 2014年每周一赛第一场
- 2015年每周一赛第六场1001. Cow Baseball
- 中大周赛 2014年每周一赛第二场 Meet and Greet
- 第一场积分赛
- 2014 多校 第一场
- 2014 多校赛 第一场
- 【每周一荐】个人电脑搭建discuz论坛【第一辑】
- 每周一书-《做自己-鬼脚七自媒体第一季》
- 2014/07/26 暑期个人赛一(每周)
- acm新生赛第一场
- DIY练习赛第一场
- 月赛_10_第一场
- 第一场个人训练赛
- 训练赛第一场总结
- 暑期个人赛第一场
- 2014 BUAA 选拔赛第一场
- 2011年第一场雪
- 被虐中成长——2014年多校训练赛第一场解题报告
- Hibernate之HQL总结
- mysql表的内连接,左连接,右连接,全连接,自然连接
- 身份证前六位地址验证
- EL表达式 (详解)
- 信号加窗
- Sicily 2014年每周一赛第一场
- java并发编程之过度同步
- Linux内核设计的艺术-前三章总结
- UML类图画法
- Java Web表示层技术:java web工作原理
- virtualbox 启动时Kernel driver not installed (rc=-1908) 错误的
- Linux内核开机保留大块内存的方法总结
- VS窗口混乱之后如何恢复问题
- 杭电OJ 1059:Dividing