AtCoder. Tenka1 Programmer Contest C,D
2017-10-01 09:53
337 查看
做了两道水题,然后看各路大神虐菜。
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
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.
there exists a solution such that h,n,w≤3500.
satisfies the condition, in the following format:
4⁄2=1⁄1+1⁄2+1⁄2.
It is allowed to use an integer exceeding 3500 in
a solution.
特水数学题,看时间和数据量知直接暴力枚举h,n凑w即可,真水。
Time limit : 2sec / Memory limit : 256MB
Score : 500 points
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.
0≤K<230
0≤Ai<230(1≤i≤N)
1≤Bi≤109(1≤i≤N)
All input values are integers.
Buy 2 and 3 to
achieve the maximum possible total utility, 8.
Buy 2 and 4 to
achieve the maximum possible total utility, 9.
特水dp题,直接枚举每一位通过xor进行状态更新,O(n)
C - 4/N
Time limit : 2sec / Memory limit : 256MBScore : 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 thatsatisfies the condition, in the following format:
h n w
Sample Input 1
Copy2
Sample Output 1
Copy1 2 2
4⁄2=1⁄1+1⁄2+1⁄2.
Sample Input 2
Copy3485
Sample Output 2
Copy872 1012974 1539173474040
It is allowed to use an integer exceeding 3500 in
a solution.
Sample Input 3
Copy4664
Sample Output 3
Copy3498 3498 3498
特水数学题,看时间和数据量知直接暴力枚举h,n凑w即可,真水。
#include <iostream> using namespace std; #define ll long long const 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 : 256MBScore : 500 points
Problem Statement
Seisu-ya, a store specializing in non-negative integers, sells N non-negativeintegers. 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≤1050≤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 K
A1 B1
:
AN BN
Outputs
Print the maximum possible sum of utilities of purchased integers.Sample Input 1
Copy3 5 3 3 4 4 2 5
Sample Output 1
Copy8
Buy 2 and 3 to
achieve the maximum possible total utility, 8.
Sample Input 2
Copy3 6 3 3 4 4 2 5
Sample Output 2
Copy9
Buy 2 and 4 to
achieve the maximum possible total utility, 9.
Sample Input 3
Copy7 14
10 5
7 4
11 4
9 83 6
6 28 9
Sample Output 3
Copy32
特水dp题,直接枚举每一位通过xor进行状态更新,O(n)
#include <iostream> using namespace std; #define ll long long const 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 - F)
- AtCoder Tenka1 Programmer Beginner Contest 解题报告
- AtCoder Tenka1 Programmer Beginner Contest D IntegerotS 数学
- AtCoder Regular Contest 075
- 【题解】AtCoder Grand Contest 016
- AtCoder Regular Contest 075 D Widespread
- AtCoder Regular Contest 077
- AtCoder Grand Contest 017 迟到记
- AtCoder Grand Contest 020 C - Median Sum (背包问题+bitset )
- AtCoder Grand Contest 012 C - Tautonym Puzzle 构造
- AtCoder Regular Contest 090
- (组合计数)AtCoder Grand Contest 018 E - Sightseeing Plan
- AtCoder Beginner Contest 087 - D People on a Line
- AtCoder Grand Contest 016 C - +/- Rectangle 构造
- AtCoder Grand Contest 004 C - AND Grid 构造
- AtCoder Grand Contest 005 E - Sugigma: The Showdown 博弈论+贪心
- AtCoder Grand Contest 006 D - Median Pyramid Hard 二分答案
- AtCoder Regular Contest 058 D - Iroha and a Grid 组合数学
- AtCoder Regular Contest 074 F - Lotus Leaves 最小割
- AtCoder Regular Contest D - Remainder Reminder 取余问题