SRM 599 div2 250 500
来源:互联网 发布:宁波知豆电动车租赁 编辑:程序博客网 时间:2024/04/30 05:01
Problem Statement
Dachshund is a popular dog breed. In this problem, a miniature dachshund is defined as a dachshund whose weight is not more than 5,000 grams.Lun the miniature dachshund loves mikan (satsuma oranges). She has just bought some mikan. You are given a vector <int>mikan. It gives the weight of all mikan she bought. For each valid i,mikan[i] is the weight of the i-th mikan in grams.
You are also given an int weight. Currently, Lun weighs weight grams. When she eats i-th mikan, her weight increases by mikan[i] grams. If she eats multiple mikan, her weight increases by their total weight. She cannot eat just a part of a mikan. In other words, if she chooses to eat a mikan, she eats it completely.
She wants to remain being a miniature dachshund. That is, she wants her weight not to exceed 5,000 grams. Under this condition, calculate and return the maximum number of mikan Lun can eat.
Definition
Class:MiniatureDachshundMethod:maxMikanParameters:vector <int>, intReturns:intMethod signature:int maxMikan(vector <int> mikan, int weight)(be sure your method is public)Constraints
-mikan will contain between 1 and 50 elements, inclusive.-Each element of mikan will be between 50 and 200, inclusive.-weight will be between 3,000 and 5,000, inclusive.Examples
0){100, 100, 100, 100, 100}
4750
Returns: 2Here, Lun weighs 4,750 grams and has bought 5 mikan, each of which weighs 100 grams. When she eats 2 of these, her weight will be 4,950 grams. She should not eat more.1)
{100, 100, 100, 100, 50}
4750
Returns: 3This time, one of the mikan is smaller. She can eat it with 2 of the 100-gram mikan. Note that her weight is allowed to be exactly 5,000 grams.2)
{120, 90, 130, 100, 110, 80}
3000
Returns: 6When she is light enough, she can eat all of the mikan she has bought.3)
{50}
5000
Returns: 0When her weight is already 5,000 grams, she should not eat anything.4)
{200, 50, 200, 50, 200, 50, 200, 50}
4800
Returns: 4
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace std;class MiniatureDachshund {public: int maxMikan(vector <int>, int);};int MiniatureDachshund::maxMikan(vector <int> mikan, int weight){ int t=mikan.size(),ans=0,v=5000-weight; sort(mikan.begin(),mikan.end()); for(int i=0;i<t&&v>0&&mikan[i]<=v;i++) { v-=mikan[i];ans++; } return ans;}//<%:testing-code%>//Powered by [KawigiEdit] 2.0!//<%:start-tests%>
Problem Statement
This problem statement contains superscipts that may not display properly outside the applet.
You are given four ints A, B, C and D. Return "divisible" (quotes for clarity) if AB is divisible by CD. Return "not divisible" otherwise.
Definition
Class:BigFatInteger2Method:isDivisibleParameters:int, int, int, intReturns:stringMethod signature:string isDivisible(int A, int B, int C, int D)(be sure your method is public)Notes
-The return value is case-sensitive.-Positive integer y divides a positive integer x if and only if there is a positive integer z such that y*z=x. In particular, for each positive integer x, both 1 and x divide x.Constraints
-A, B, C and D will each be between 1 and 1,000,000,000 (109), inclusive.Examples
0) 6121Returns: "divisible"Here, AB = 61 = 6 and CD = 21 = 2. 6 is divisible by 2.1) 2161Returns: "not divisible"2 is not divisible by 6.2) 100000000010000000001000000000200000000Returns: "divisible"Now the numbers are huge, but we can see that AB is divisible by CD from the fact that A=C and B>D.3) 81004200Returns: "not divisible"We can rewrite 8100 as (23)100 = 2300. Similarly, 4200 = (22)200 = 2400. Thus, 8100 is not divisible by 4200.4) 99999993710000000009999999291Returns: "not divisible"Here A and C are distinct prime numbers, which means AB cannot have C as its divisor.5) 2241Returns: "divisible"This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using namespace std;class BigFatInteger2 {public: string isDivisible(int, int, int, int);};string BigFatInteger2::isDivisible(int A, int B, int C, int D){ string div("divisible"),nodiv("not divisible"); map<int,long long int> primeA,primeB; int ta=sqrt(A),tc=sqrt(C); for(int i=2;i<=ta;i++) { long long int cnt=0; while(A%i==0) { A/=i; cnt++; } if(cnt) { primeA.insert(make_pair(i,(long long )cnt*B)); } } if(A!=1LL) primeA.insert(make_pair(A,(long long )B)); bool flag=true; for(int i=2;i<=tc;i++) { long long int cnt=0; while(C%i==0) { C/=i; cnt++; } if(cnt) { if(primeA.count(i)==0) { flag=false;break; } else if(primeA[i]<(long long )D*cnt) { flag=false;break; } } } if(C!=1LL&&flag) { if(primeA.count(C)==0||primeA[C]<D) { flag=false; } } if(flag) { return div; } else return nodiv;}//<%:testing-code%>//Powered by [KawigiEdit] 2.0!//<%:start-tests%>
- SRM 599 div2 250 500
- srm 535 div2 250&500
- SRM 599 DIV2 950
- SRM 398 DIV2 [250]
- SRM 399 DIV2 [250]
- SRM 387 DIV2 [250]
- SRM 400 DIV2 [250]
- SRM 586 DIV2 250
- SRM 597 DIV2 250
- SRM 397 DIV2 [500]
- SRM 400 DIV2 [500]
- SRM 421Div2 500
- SRM 457 Div2 500
- SRM 586 DIV2 500
- SRM 597 DIV2 500
- TC SRM div2 500
- Topcoder srm div2 500
- topcoder SRM 543 div2 250
- package-info.java文件的详细介绍
- 牛人共享的各种互联网资料
- wxidgets知识点
- mac 删除svn
- ASP.NET 页面错误: "asp.net XML Parsing Error: no element found Line Number 1, Column 1"
- SRM 599 div2 250 500
- Linux中epoll用法总结
- Qt学习——堆栈窗体QStackedWidget类
- NPAPI开发详解,Windows版
- oracle常用函数
- ehcache memcache redis 三大缓存男高音
- unicode编码简单剖析
- AfxMessageBox()和MessageBox()
- 查找某应用后kill全局命令