题目
a
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,cnt=0,m,ctt=0;
string s;
ll idx;
ll a[11];
map<string ,ll>mp;
void solve(){
cin>>n;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=5;j++){
cin>>s;
if(mp[s]==0) cnt++;
mp[s]=1;
}
}
cin>>m;
for(ll i=1;i<=m;i++){
cin>>s>>idx;
ctt+=mp[s];
a[idx]++;
}
ll ans=a[1];
for(ll i=1;i<=5;i++){
ans=min(ans,a[i]);
}
cout<<min(ans,ctt)<<endl;
return ;
}
int main()
{
ll t;
// cin>>t;
t=1;
while(t--){
solve();
}
return 0;
}
d 状态压缩 dp
#include<bits/stdc++.h>
using namespace std;
#define ll int
const ll maxn =2e6+20;
pair<ll,ll>p;
vector<pair<ll,ll> >v[maxn];
ll a[maxn];
ll vis[maxn];
ll f[maxn];
ll st=0;
void add(ll mid ,ll l,ll r){
// p=make_pair(l,r);
v[mid].push_back({l,r});
// p=make_pair(r,l);
v[mid].push_back({r,l});
return ;
}
void init(){
memset(f, -0x3f, sizeof f);
f[0] = 0, vis[0] = 1;
for(ll i=0;i<19;i++) cin>>a[i];
add(1, 0, 2);
add(3, 0, 7);
add(4, 0, 9), add(4, 1, 8), add(4, 3, 5);
add(5, 1, 10), add(5, 2, 9), add(5, 4, 6);
add(6, 2, 11);
add(8, 3, 13), add(8, 4, 12), add(8, 7, 9);
add(9, 4, 14), add(9, 5, 13), add(9, 8, 10);
add(10, 5, 15), add(10, 6, 14), add(10, 9, 11);
add(12, 7, 16);
add(13, 8, 17), add(13, 9, 16), add(13, 12, 14);
add(14, 9, 18), add(14, 10, 17), add(14, 13, 15);
add(15, 11, 18);
add(17, 16, 18);
return ;
}
ll dfs(ll state){
if(vis[state]==1) return f[state];
for(ll i=0;i<19;i++){
if(!(state >> i & 1)) continue;
f[state] = max(f[state], dfs(state - (1 << i)));
}
for(ll i=0;i<19;i++){
if((state>>i&1)!=0){
ll len=v[i].size();
for(ll j=0;j<len;j++){//jump by a thing
ll p=v[i][j].first;
ll q=v[i][j].second;
if(( ( state>>p&1 )!=0 )&&(( state>>q&1 )==0)){
//p有棋 mid有棋 q没有棋
f[state]=max(f[state],dfs(state-(1<<i)-(1<<p)+(1<<q))+a[i]);
}
}
}
}
vis[state]=1;
return f[state];
}
void solve(){
st=0;
string s="";
string temp;
for(ll i=1;i<=5;i++){
cin>>temp;
s+=temp;
}
for(ll i=0;i<19;i++){
char c=s[i];
if(c=='#'){
st+=1<<i;
}
// tp<<=1;
}
cout<<f[st]<<endl;
return ;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
init();
// for(ll i=0;i<19;i++){
// cout<<a[i]<<' ';
// }cout<<endl;
for(ll i=0;i<19;i++){
st+=1<<i;
// tp<<=1;
}
dfs((1<<19)-1);
ll t;
cin>>t;
while(t--){
solve();
}
return 0;
}
e 模拟
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
const ll maxn=101;
ll a[maxn];
void solve(){
cin>>n>>k;
for(ll i=1;i<=n;i++){
cin>>a[i];
}
ll cnt=n;
ll p=a[n];
ll q=a[n-1];
if(p>=q){
cout<<"Python will never be faster than C++"<<endl;
return ;
}
while(1){
cnt++;
ll t=max((ll)(0), (2*p-q) );
if(t<k){
cout<<"Python 3."<<cnt<<" will be faster than C++"<<endl;
return ;
}
q=p;
p=t;
}
return ;
}
int main()
{
ll t=1;
while(t--){
solve();
}
return 0;
}
i 优先队列 二分 贪心
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=5e4+10;
ll up[101];
ll a[maxn];
ll b[maxn];
ll n,k;
struct cmp{
bool operator()(const ll &x ,const ll &y) const{
return x<y;
}
};
priority_queue<ll,vector<ll>,cmp>pr;
void init(){
up[1]=1;
for(ll i=2;i<=20;i++){
up[i]=up[i-1]*2;
}
// for(ll i=1;i<=20;i++){
// cout<<up[i]<<' ';
// }
// cout<<endl;
return ;
}
ll check(ll x){//符合return 1 不符合 return 0
while(pr.empty()!=1){
pr.pop();
}
for(ll i=1;i<=n;i++){
pr.push(a[i]*x);
}
ll idx=k;
ll t=b[idx];//当前数量
while(pr.empty()!=1&&idx!=0){
ll tp=pr.top();
// cout<<"tp: "<<tp<<endl;
pr.pop();
if(tp>up[idx]){//tp不能结束
ll num=tp/up[idx];
if(num<t){//没用完
t-=num;
tp-=num*up[idx];
}else {//不够
tp-=up[idx]*t;
idx--;
t=b[idx];
}
}else {//直接用完
t--;
if(t==0){
idx--;
t=b[idx];
}
tp=0;
}
if(tp>0){
pr.push(tp);
// cout<<"push: "<<tp<<endl;
}
}
if(pr.empty()==1){
// cout<<x<<" YES"<<endl;
return 1;
}else return 0;
}
void solve(){
ll s1=0,s2=0;
cin>>n>>k;
for(ll i=1;i<=n;i++){
cin>>a[i];
s1+=a[i];
}
for(ll i=1;i<=k;i++){
cin>>b[i];
s2+=(b[i]*up[i]);
}
ll l=0,r=s2/s1+100;
// cout<<s1<<' '<<s2<<endl;
// cout<<l<<" "<<r<<endl;
while(l<r){
ll mid =l+(r-l+1)/2;
// cout<<l<<' '<<r<<endl;
// cout<<"mid: "<<mid<<endl;
if(check(mid)==1){//ok
l=mid;
}else{//no
r=mid-1;
}
}
cout<<l<<endl;
return ;
}
int main()
{
ll t;
cin>>t;
init();
while(t--){
solve();
}
return 0;
}
j 博弈论
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
const ll maxn=1e5+10;
ll a[maxn];
struct cmp2{
bool operator()(const ll &x,const ll & y)const {
return x>y;
}
};
priority_queue<ll,vector<ll>,cmp2>pr;
map<ll,ll>mp;
ll cmp1(ll x,ll y){
return x<y;
}
void solve(){
ll ans=0;
while(pr.empty()!=1){
pr.pop();
}
mp.clear();
cin>>n>>k;
for(ll i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n,cmp1);
pr.push(-1);
for(ll i=1;i<=k;i++){
ll x,y;
cin>>x>>y;
if(y==0){
pr.push(x);
}else {
mp[x]=y;
}
}
ll tp;
for(ll i=1;i<=n;i++){
while(pr.empty()!=1){
if(a[i]>pr.top()){
tp=pr.top();
pr.pop();
}else {
break;
}
}
ans+=(a[i]-tp-1);
if(mp[tp+1]!=0){
mp[tp+1]--;
if(mp[tp+1]==0){
pr.push(tp+1);
}
}
}
// cout<<ans<<endl;
if(ans&1) cout<<"Pico"<<endl;
else cout<<"FuuFuu"<<endl;
return ;
}
int main()
{
ll t;
cin>>t;
while(t--){
solve();
}
return 0;
}