思路:
简单博弈.每次只取一个即可.
因此胜利先手胜利条件:$n_1>n_2$
AC Code:
#include<bits/stdc++.h>
#pragma optimize(2)
#define endl '\n'
#define ll() to_ullong()
#define string() to_string()
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef unsigned long long ull;
const int M=2010;
const int P=13331;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int N=2e6+10;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
void solve()
{
int n1,n2,k1,k2;
cin>>n1>>n2>>k1>>k2;
if(n2>=n1)cout<<"Second"<<endl;
else cout<<"First"<<endl;
return ;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("test.in","r",stdin);
solve();
return 0;
}
思路:
贪心的考虑,将能变的更小的先变小.
前提是$k$张朝上.
AC Code:
#include<bits/stdc++.h>
#pragma optimize(2)
#define endl '\n'
#define ll() to_ullong()
#define string() to_string()
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef unsigned long long ull;
const int M=2010;
const int P=13331;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int N=2e6+10;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
struct node{
int x,y;
int dif,id;
bool operator<(const node &a)const
{
return a.dif<dif;
}
};
bool vis[N];
void solve()
{
int n,k;
cin>>n>>k;
vector<node>a(n+1);
for(int i=1;i<=n;i++)cin>>a[i].x;
for(int i=1;i<=n;i++)cin>>a[i].y;
for(int i=1;i<=n;i++)
{
if(a[i].x>a[i].y)a[i].dif=a[i].x-a[i].y;
else a[i].dif=0;
a[i].id=i;
}
sort(a.begin()+1,a.end());
int cur=n;
for(int i=1;i<=n;i++)
{
if(a[i].dif>0&&cur>k)vis[i]=true,cur--;
}
ll ans=0;
for(int i=1;i<=n;i++)
if(vis[i])ans+=a[i].y;
else ans+=a[i].x;
cout<<ans<<endl;
return ;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("test.in","r",stdin);
solve();
return 0;
}
思路:哈希表/字符串.
由于字符串长度较短.枚举单个字符串所有的可能字串即可.
不过需要注意的是:一个子串可能在,一个完整的字符串中多次出现,但是只会做一次计数.
AC Code:
#include<bits/stdc++.h>
#pragma optimize(2)
#define endl '\n'
#define ll() to_ullong()
#define string() to_string()
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef unsigned long long ull;
const int M=2010;
const int P=13331;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int N=2e6+10;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
map<string,PII>mp;
map<string,bool>Q;
void solve()
{
int n;cin>>n;
vector<string>a(n+1);
for(int i=1;i<=n;i++)
{
string s;cin>>s;
a[i]=s;
Q.clear();
for(int j=0;j<s.size();j++)
for(int k=j;k<s.size();k++)
{
string tmp=s.substr(j,k-j+1);
if(!Q[tmp])mp[tmp].first=i,mp[tmp].second++,Q[tmp]=true;//只计算一次
}//枚举所有子串
}
int q;cin>>q;
while(q--)
{
string s;cin>>s;
// cout<<s<<endl;
if(mp[s].second!=0)cout<<mp[s].second<<' '<<a[mp[s].first]<<endl;
else cout<<0<<' '<<"-"<<endl;
}
return ;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("test.in","r",stdin);
solve();
return 0;
}