AtCoder. Tenka1 Programmer Contest C,D
来源:互联网 发布:五五开的淘宝店叫什么 编辑:程序博客网 时间:2024/06/06 08:34
做了两道水题,然后看各路大神虐菜。
C - 4/N
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
You are given an integer N.
Find a triple of positive integers h, n and w such that 4⁄N=1⁄h+1⁄n+1⁄w.
If there are multiple solutions, any of them will be accepted.
Constraints
- It is guaranteed that, for the given integer N, there exists a solution such that h,n,w≤3500.
Inputs
Input is given from Standard Input in the following format:
N
Outputs
Print a triple of positive integers h, n and w that satisfies the condition, in the following format:
h n w
Sample Input 1
2
Sample Output 1
1 2 2
4⁄2=1⁄1+1⁄2+1⁄2.
Sample Input 2
3485
Sample Output 2
872 1012974 1539173474040
It is allowed to use an integer exceeding 3500 in a solution.
Sample Input 3
4664
Sample Output 3
3498 3498 3498
#include <iostream>using namespace std;#define ll long longconst int maxn=3501;ll n;int main(int argc, const char * argv[]) { ll a,b; ll c; scanf("%lld",&n); for(a=1;a<=maxn;++a) for(b=1;b<=maxn;++b){ ll x=4*a*b-n*b-n*a; ll y=n*a*b; if(x>0 && y%x==0) { c=y/x; cout<<a<<" "<<b<<" "<<c<<endl; return 0; } } return 0;}
D - IntegerotS
Time limit : 2sec / Memory limit : 256MB
Score : 500 points
Problem Statement
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is Ai and has a utility of Bi. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
- 1≤N≤105
- 0≤K<230
- 0≤Ai<230(1≤i≤N)
- 1≤Bi≤109(1≤i≤N)
- All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N KA1 B1:AN BN
Outputs
Print the maximum possible sum of utilities of purchased integers.
Sample Input 1
3 53 34 42 5
Sample Output 1
8
Buy 2 and 3 to achieve the maximum possible total utility, 8.
Sample Input 2
3 63 34 42 5
Sample Output 2
9
Buy 2 and 4 to achieve the maximum possible total utility, 9.
Sample Input 3
7 1410 57 411 49 83 66 28 9
Sample Output 3
32
#include <iostream>using namespace std;#define ll long longconst int maxn=1e5+5;int n,k,a[maxn],b[maxn];int main(int argc, const char * argv[]) { scanf("%d%d",&n,&k); k++; for(int i=0;i<n;++i) scanf("%d%d",&a[i],&b[i]); int cur=0; ll tmp=0; ll ans=0; for(int bit=30;bit>=0;--bit){ if(k&(1<<bit)){ tmp=0; cur^=1<<bit; for(int i=0;i<n;++i){ if((a[i]&cur)==0) tmp+=b[i]; ans=max(ans,tmp); } cur^=1<<bit; } else cur^=1<<bit; } cout<<ans<<endl; return 0;}
- AtCoder. Tenka1 Programmer Contest C,D
- Tenka1 Programmer Contest-D
- AtCoder Tenka1 Programmer Beginner Contest D IntegerotS 数学
- Atcoder Tenka1 Programmer Beginner Contest IntegerotS 【异或+思维】
- Tenka1 Programmer Contest
- AtCoder Regular Contest 079 C D E
- AtCoder Regular Contest 080 C , D
- 【Tenka1 Programmer Contest 2017 F】ModularPowerEquation!!(欧拉定理)
- 【AtCoder】(AtCoder Grand Contest 006)D
- AtCoder AtCoder Beginner Contest 063 D
- atcoder AtCoder Regular Contest 084 D
- AtCoder Regular Contest 069 D
- Atcoder Grand Contest 013D
- AtCoder Regular Contest 073 D
- AtCoder Beginner Contest 061 D
- AtCoder Regular Contest 077-D
- AtCoder Beginner Contest 066 D
- AtCoder Regular Contest 078 D
- 公众号投稿说明
- c++纯虚函数和抽象类
- 是否同一棵二叉搜索树
- IT行业技术牛逼就可以无视学历?
- java拼接get请求的url请求地址
- AtCoder. Tenka1 Programmer Contest C,D
- 内部类
- 一分钟了解“英语difference 后不能加among,多个对象也不行”
- 国庆长假前不妨先来做完这份 JavaScript 测验吧!因为......
- 最短路的优先队列的优化
- 学习Docker(2017-9-30)
- 联合索引(复合索引)在B+树上的结构
- java基础之循环三剑客!
- reg51.h源码分析笔记