我喜欢给自己压力,必须得定一个很高的目标,逼自己朝着这个目标前进,不管会不会实现,都是一个动力。 ----喻言
链接:https://ac.nowcoder.com/acm/problem/15911
来源:牛客网
题目描述
现有n组人,m个地点,给出每组人的人数,每个地点可容纳的最大人数和选择的价格
要求一种方式,使得每组人都到一个各不相同的地点,最小化选择的价格
每个队伍的人都要在同一个地方每个地方只能有一个队伍
输入描述:
第一行n,m 第二行n个数,表示每组的人数 接下来m行,每行两个数,表示可容纳的最大人数和选择的价格
输出描述:
输出最小化选择的价格,无解输出-1
示例1
输入
复制
3 4 2 3 4 1 2 2 3 3 4 4 5
输出
复制
12
备注:
所有数据小于1e5
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=10010;
int const mod=1e9+7;
const int maxn=1e5+10;
int n,m,a[maxn];
priority_queue<int,vector<int>,greater<int> >s;
struct node
{
int a;
int b;
}b[maxn];
bool cmp(node x,node y)
{
return x.a<y.a;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d%d",&b[i].a,&b[i].b);
sort(a+1,a+n+1);
sort(b+1,b+m+1,cmp);
int jg=0;
for(int i=n,j=m;i>0;i--)
{
for(;b[j].a>=a[i];j--)
s.push(b[j].b);
if(s.empty())
{
printf("-1\n");
return 0;
}
jg+=s.top();
s.pop();
}
printf("%d\n",jg);
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/15931
来源:牛客网
题目描述
We define an element aia_{i}ai in a sequence "good", if and only if there exists aja_{j}aj (1≤j<i) such that aj<aia_{j}<a_{i}aj<ai.
Given a permutation p of integers from 1 to n. Remove an element from the permutation such that the number of "good" elements is maximized.
输入描述:
The input consists of several test cases. The first line of the input gives the number of test cases,T(1≤T≤103)T(1\leq T \leq 10^3)T(1≤T≤103). For each test case, the first line contains an integer n(1≤n≤106)n(1\leq n \leq 10^6)n(1≤n≤106), representing the length of the given permutation. The second line contains n integersp1,p2,…,pn (1≤pi≤n)(1\leq p_{i} \leq n)(1≤pi≤n), representing the given permutation p. It's guaranteed that ∑n≤2∗107\sum_{}^{}{n} \leq 2 *10^7∑n≤2∗107.
输出描述:
For each test case, output one integer in a single line, representing the element that should be deleted. If there are several answers, output the minimal one.
示例1
输入
复制
2 1 1 5 5 1 2 3 4
输出
复制
1 5
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=10010;
int const mod=1e9+7;
const int maxn=1000010;
int n,a,ls,jg,mx,mi;
int c[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
mx=inf,mi=inf;
for(int i=1;i<=n;i++)
c[i]=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
if(a<=mi)
{
mx=mi;
mi=a;
}
else if(a>=mi&&a<mx)
{
c[mi]++;
c[a]++;
mx=a;
}
else if(a>=mx)
c[a]++;
}
ls=inf,jg=mi;
for(int i=1;i<=n;i++)
{
if(c[i]<ls)
{
ls=c[i];
jg=i;
}
}
printf("%d\n",jg);
}
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/15933
来源:牛客网
题目描述
Alice and Bob are playing a stone game. There are n piles of stones. In each turn, a player can remove some stones from a pile (the number must be positive and not greater than the number of remaining stones in the pile). One player wins if he or she remove the last stone and all piles are empty. Alice plays first.
To make this game even more interesting, they add a new rule: Bob can choose some piles and remove entire of them before the game starts. The number of removed piles is a nonnegative integer, and not greater than a given number d. Note d can be greater than n, and in that case you can remove all of the piles.
Let ans denote the different ways of removing piles such that Bob are able to win the game if both of the players play optimally. Bob wants you to calculate the remainder of ans divided by109+7.
输入描述:
The first line contains an integer T, representing the number of test cases. For each test cases, the first line are two integers n and d, which are described above. The second line are n positive integersai, representing the number of stones in each pile. T≤5,n≤103,d≤10,ai≤103T \leq 5 ,n \leq 10^3 ,d \leq 10, a_{i}\leq10^3T≤5,n≤103,d≤10,ai≤103
输出描述:
For each test case, output one integer (modulo109+7.) in a single line, representing the number of different ways of removing piles that Bob can ensure his victory.
示例1
输入
复制
2 5 2 1 1 2 3 4 6 3 1 2 4 7 1 2
输出
复制
2 5
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=10010;
int const mod=1e9+7;
const int maxn=1e5+5;
int dp[1100][12][1100];
int t,n,d;
int main()
{
cin>>t;
while(t--)
{
cin>>n>>d;
memset(dp,0,sizeof(dp));
for(int i=0;i<=n; i++)
dp[i][0][0]=1;
ll x,sum=0;
for(int i=1;i<= n; i++)
{
cin>>x;
sum^=x;
for(int j=1;j<=d;j++)
{
for(int k=0; k<1024; k++)
dp[i][j][k]=(dp[i-1][j][k]+dp[i-1][j-1][k^x])%mod;
}
}
ll jg=0;
for(int i=0 ;i<=d; i++)
jg=(jg+dp[n][i][sum])%mod;
cout<<jg<<endl;
}
return 0;
}