CodeForces - 808F Card Game (随机化大法)
2017-05-23 14:36
447 查看
F. Card Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Digital collectible card games have become very popular recently. So Vova decided to try one of these.
Vova has n cards in his collection. Each of these cards is characterised by its power pi,
magic number ci and
level li.
Vova wants to build a deck with total power not less than k, but magic numbers may not allow him to do so — Vova can't place two cards
in a deck if the sum of the magic numbers written on these cards is a prime number. Also Vova cannot use a card if its level is greater than the level of Vova's character.
At the moment Vova's character's level is 1. Help Vova to determine the minimum level he needs to reach in order to build a deck with the required
total power.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100000).
Then n lines follow, each of these lines contains three numbers that represent the corresponding card: pi, ci and li (1 ≤ pi ≤ 1000,1 ≤ ci ≤ 100000, 1 ≤ li ≤ n).
Output
If Vova won't be able to build a deck with required power, print - 1. Otherwise print the minimum level Vova has to reach in order to build
a deck.
Examples
input
output
input
output
题意:给你一列数,有三个属性,等级,价值,特征值,从中选出一些数,使这些数的价值和不低于
给定值,并且任意两个数的特征值相加不为素数,求这些满足要求的最小等级
解:因为不知道相斥的俩个数留哪一个数,所以循环随机M次数组,把答案搜出来
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Digital collectible card games have become very popular recently. So Vova decided to try one of these.
Vova has n cards in his collection. Each of these cards is characterised by its power pi,
magic number ci and
level li.
Vova wants to build a deck with total power not less than k, but magic numbers may not allow him to do so — Vova can't place two cards
in a deck if the sum of the magic numbers written on these cards is a prime number. Also Vova cannot use a card if its level is greater than the level of Vova's character.
At the moment Vova's character's level is 1. Help Vova to determine the minimum level he needs to reach in order to build a deck with the required
total power.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100000).
Then n lines follow, each of these lines contains three numbers that represent the corresponding card: pi, ci and li (1 ≤ pi ≤ 1000,1 ≤ ci ≤ 100000, 1 ≤ li ≤ n).
Output
If Vova won't be able to build a deck with required power, print - 1. Otherwise print the minimum level Vova has to reach in order to build
a deck.
Examples
input
5 8 5 5 1 1 5 4 4 6 3 1 12 4 3 12 1
output
4
input
3 7 4 4 1 5 8 2 5 3 3
output
2
题意:给你一列数,有三个属性,等级,价值,特征值,从中选出一些数,使这些数的价值和不低于
给定值,并且任意两个数的特征值相加不为素数,求这些满足要求的最小等级
解:因为不知道相斥的俩个数留哪一个数,所以循环随机M次数组,把答案搜出来
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 3e5+10; const int M = 3069; int num[4]; int prime , a , lx , b ; struct node { int v, c, level; } p ; int cmp(node A,node B) { return A.level<B.level; } int n, k; int main() { memset(a,0,sizeof(a)); int cnt=0; a[0]=a[1]=1; for(int i=0; i<N; i++) { if(a[i]) continue; for(int j=2*i; j<N; j+=i) a[j]=1; } scanf("%d %d", &n, &k); for(int i=1; i<=n; i++) scanf("%d %d %d", &p[i].v,&p[i].c,&p[i].level); sort(p+1,p+n+1,cmp); memset(lx,0,sizeof(lx)); for(int i=1; i<=n; i++) lx[p[i].level]=i; int ans=0, sum, c; for(int i=1; i<=n; i++) { if(!lx[i]) continue; if(i==4) { int l; l=0; } for(int h=0; h<M; h++) { random_shuffle(p+1,p+lx[i]+1); c=0, sum=0; for(int j=1; j<=lx[i]; j++) { int flag=0; for(int q=0;q<c;q++) { if(!a[p[j].c+p[b[q]].c]) { flag=1; break; } } if(!flag) { b[c++]=j; sum+=p[j].v; } } if(sum>=k) { printf("%d\n",i); return 0; } } } printf("-1\n"); return 0; }
相关文章推荐
- CodeForces 527C(set大法好)
- Codeforces 510D. Fox And Jumping By Assassin 暴力大法好
- Codeforces 808F Card Game【思维建图+最小割】
- Codeforces 279B Books(dp大法好)
- Codeforces 808F Card Game(和是素数二分图建图+二分图带权最大独立集)
- CodeForces 825G Educational Round #25 G :建树选根大法+O1大法+iostream解绑了还是慢
- Codeforces 808F Card Game
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
- Codeforces:68A-Irrational problem(暴力大法好)
- [随机化 构造] Codeforces 717H Bubble Cup 9 - Finals H. Pokermon League challenge
- CodeForces 527C(set大法好)
- Codeforces 844 D Interactive LowerBound(随机化)
- codeforces 398A
- Codeforces 569 A. Music ( 模拟 )
- CodeForces 663A Rebus
- CodeForces 723F【DFS瞎搞】
- Codeforces 86C Genetic engineering (AC自己主动机+dp)
- codeforces 855C 树DP
- Codeforces 401A Vanya and Cards(水题)
- Codeforces 300A Array