CCPC 2022济南站+2020威海站+2019秦皇岛站+2022绵阳站(部分)(暑假集训)

news2024/9/24 5:23:12

目录

Tower

Frozen Scoreboard

  Identical Parity​编辑

 Best Carry Player

Stack Sort

Invoker

 MUV LUV EXTRA

 Forest Program

Angle Beats

Catch You Catch Me


Tower

思路:

 提前进行/2的预处理操作,操作之后 ,在记录下要达到一样的步骤,由于可以可删除m座塔,所以此时,将步骤最多的删除,就是答案了



#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
const ll hash_num = 3e9+9;
ll n,m,ca;
 ll arr[N],brr[N],crr[N];
//  int h[N],ne[N],e[N],w[N],idx;

void solve()
{	
    map<ll,ll>mp,mmp;
    cin >> n >> m;
    rep(i,1,n)
    {
      ll x;
      cin >> x;
      arr[i] = x;
      mp[x]++;
      while(x)
      {
        mmp[x]++;
        x>>=1;
      }
    }
    ll ans = INF;
    for(auto it:mmp)
    {
      rep(i,0,n)brr[i]=0;
      ll ant = 0;
      ll cnt = 0;
      for(auto iit:mp)
      {
        if(iit.first==it.first)continue;
        ll x=iit.first,y=iit.second;
        ll res = 0;
        if(x < it.first)
        {
          res += (it.first-x)*y;
          ant += res;
          while(y--)
          {
            brr[++cnt]=it.first-x;
          }
          continue;
        }
        while(x!=it.first)
        {
          if(x / 2 >= it.first)
          { 
            x/=2;
            res++;
          }else{
            res += min(x - it.first, 1 + it.first - x / 2);
            x=it.first;
          }
        }
        ant += res *y;
        while(y--)brr[++cnt]=res;
      }
      sort(brr+1,brr+1+cnt);
      per(j,cnt,cnt-m+1)
      {
        ant -=brr[j];
        if(j==1)break;
      }
      ans=min(ans,ant);
    }
    cout <<ans<<endl;
}




int main()
{
   IOS;
   ll _;
    _=1;
   // scanf("%d",&t);
    cin>>_;
    ca=1;
    while(_--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}

Frozen Scoreboard

 

 

思路:
        纯大模拟,写出来了是好题,写不出来,这什么lj题(气急败坏)

 来自大佬的说法就是硬写,然后加上dfs

这是佬码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll haoye=0;
struct vis{
	ll t,s;
};
vis a[1005];
vector<string>d[1005];
vector<ll>q[1005];
vector<ll>h[1005];
ll st[15];
ll n,m;
ll check(ll x){
	ll z=0,w=0;
	ll ss=0;
	for(int i=0;i<d[x].size();i++){
		if(d[x][i]=="+"){
			z++;
			ss=ss+h[x][i]+(q[x][i]-1)*20;
		}
		else if(d[x][i]=="?"){
			w++;
		}
	}
	// cout<<z<<" "<<w<<" "<<st;
	if(z>a[x].s)return 0;
	if(z==a[x].s){
		if(ss!=a[x].t)return 0;
		else return 1;
	}
	if(z+w>=a[x].s){
		return 2;
	}
	return 0;
}
void dfs(ll x,ll cnt,ll idx){
	if(haoye==1)return ;
	if(cnt==0){
		vector<ll>md;
		ll ssum=0;
		ll hh=0;
		for(int i=0;i<m;i++){
			if(d[x][i]=="+"){
				ssum=ssum+h[x][i]+(q[x][i]-1)*20;
			}
			else if(d[x][i]=="?"){
				if(st[i]==1){
					ssum=ssum+240+(h[x][i]-q[x][i])*20;
					hh=hh+59+(q[x][i]-1)*20;
				}
			}
			// cout<<i<<" "<<ssum<<" "<<hh<<"\n";
		}
		if(a[x].t>=ssum&&a[x].t<=ssum+hh) {
			haoye=1;
			cout<<"Yes\n";
			ll tmp=a[x].t-ssum;
			for(int i=0;i<m;i++){
				if(d[x][i]=="."){
					cout<<".\n";
					continue;
				}
				else if(d[x][i]=="+"){
					cout<<"+ ";
					cout<<q[x][i]<<"/"<<h[x][i]<<"\n";
				}
				else if(d[x][i]=="-"){
					cout<<"- "<<q[x][i]<<"\n";
				}
				else {
					if(st[i]==0){
						cout<<"- "<<h[x][i]<<"\n";
						continue;
					}
					if(tmp==0){
						cout<<"+ "<<h[x][i]-q[x][i]+1<<"/240\n";
					}
					else if(tmp<=59){
						cout<<"+ "<<h[x][i]-q[x][i]+1<<"/"<<240+tmp<<"\n";
						tmp=0;
					}
					else {
						ll hh=h[x][i]-q[x][i]+1;
						while(tmp>=20&&hh<h[x][i]){
							tmp-=20;
							hh++;
						}
						if(tmp<=59){
							cout<<"+ "<<hh<<"/"<<240+tmp<<"\n";
							tmp=0;
						}
						else {
							cout<<"+ "<<hh<<"/299"<<"\n";
							tmp-=59;
						}
					}
				}
			}
		}
		return ;
	}
	for(int i=idx;i<m;i++){
		if(st[i]==0){
			st[i]=1;
			if(haoye==1)return ;
			dfs(x,cnt-1,i+1);
			st[i]=0;
			if(haoye==1)return ;
		}
	}
}
void vision(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i].s>>a[i].t;
		string op;
		for(int j=1;j<=m;j++){
			cin>>op;
			if(op=="."){
				d[i].push_back(op);
				q[i].push_back(0);
				h[i].push_back(0);
			}
			else if(op=="+"){
				d[i].push_back(op);
				string hh;
				cin>>hh;
				ll mm=0;
				for(int k=0;k<hh.length();k++){
					if(hh[k]!='/'){
						mm=mm*10+hh[k]-'0';
					}
					else {
						q[i].push_back(mm);
						mm=0;
					}
				}
				h[i].push_back(mm);
			}
			else if(op=="?"){
				d[i].push_back(op);
				ll caiq,caih;
				cin>>caiq>>caih;
				q[i].push_back(caiq);
				h[i].push_back(caih);
			}
			else {
				d[i].push_back(op);
				ll cai;
				cin>>cai;
				q[i].push_back(cai);
				h[i].push_back(0);
			}
		}
	}
	// for(int i=1;i<=n;i++){
	// 	for(int j=0;j<m;j++){
	// 		cout<<d[i][j]<<" ";
	// 		cout<<" "<<q[i][j]<<" "<<h[i][j]<<"\n";
	// 	}
	// }
	for(int i=1;i<=n;i++){
		if(check(i)==0){cout<<"No\n";continue;}
		else if(check(i)==1){
			cout<<"Yes\n";
			for(int j=0;j<m;j++){
				if(d[i][j]=="."){
					cout<<".\n";
					continue;
				}
				else if(d[i][j]=="+"){
					cout<<"+ ";
					cout<<q[i][j]<<"/"<<h[i][j]<<"\n";
				}
				else if(d[i][j]=="-"){
					cout<<"- "<<q[i][j]<<"\n";
				}
				else {
					cout<<"- "<<h[i][j]<<"\n";
				}
			}
		}
		else {
			ll cnt=0;
			for(int j=0;j<m;j++){
				if(d[i][j]=="+"){st[j]=1;cnt++;}
				else if(d[i][j]=="?")st[j]=0;
				else 
					st[j]=1;
			}
			haoye=0;
			// cout<<a[i].s-cnt<<" ";
			dfs(i,a[i].s-cnt,0);
			if(haoye==0)cout<<"No\n";
		}
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t=1;
    // cin>>t;
    // scanf("%lld",&t);
    while(t--)
        vision();
    return 0;
}

  Identical Parity

 思路:

        



#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
const ll hash_num = 3e9+9;
ll n,m,ca;
 ll arr[3000];
//  int h[N],ne[N],e[N],w[N],idx;

unordered_map<ll,ll>mp;
ll Hash(ll x, ll y)
{
    // if(x==0)y=abs(y);
    // return x*233333333+y;
    return x*hash_num+y;
}
 

ll gcdd(ll a, ll b)
{
      // while(b^=a^=b^=a%=b);    
      // return a;
      if(b==0)return a;
      return gcdd(b,a%b);
}

struct noda
{
  /* data */
  ll x,y;
}noda[3000],q[3000];



void solve()
{	
     cin >> n>> m;
     if(m%2==0)
     {
      yes;
     }else
     {
        ll ant=(n+1)/2-(m+1)/2*(n/m);
        ll cnt=n/2-m/2*(n/m);
        if(ant>=0 && cnt>=0 && ant<=(m+1)/2 &&cnt<=m/2)
        {
          yes;
        }else{
          no;
        }
     }
}




int main()
{
   IOS;
   ll t;
    t=1;
   // scanf("%d",&t);
    cin>>t;
    ca=1;
    while(t--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}

 Best Carry Player

思路:

        签到题了属于;就进位+1就行



#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
ll n,m,ca;
 ll arr[N],brr[N],crr[N];
//  int h[N],ne[N],e[N],w[N],idx;


// ll get_len(ll x1,ll y1,ll x2 ,ll y2)
// {
//   return abs(x1-x2)+abs(y1-y2);
// }

ll ss(ll a,ll b)
{
  if(b>a)swap(a,b);
  ll res =0;
  int f =0;
  while(a)
  {
    int x=a%10,y=b%10;
    if(x+y+f>9)f=1;
    else f =0;
    res += f;
   // f = 0;
    a/=10,b/=10;
  }
  return res;
}
void solve()
{	
    cin >> n;
    ll ans =0;
    ll num =0;
    rep(i,1,n)
    {
      ll x;
      cin >> x;
      ans += ss(x,num);
      num += x;
    }
    cout << ans <<endl;
}




int main()
{
   IOS;
   ll t;
    t=1;
   // scanf("%d",&t);
    cin>>t;
    ca=1;
    while(t--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}

Stack Sort

思路:
        记录,比当前大的有没有入栈,没入栈就ans++; 



#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
ll n,m,ca;
 ll arr[N],brr[N],crr[N];
//  int h[N],ne[N],e[N],w[N],idx;


// ll get_len(ll x1,ll y1,ll x2 ,ll y2)
// {
//   return abs(x1-x2)+abs(y1-y2);
// }


void solve()
{	
    cin >> n;
    int flag = 0;
    ll ans =0;
    //memset(brr,0,sizeof(brr));
    map<ll,ll>mp;
    rep(i,1,n)
    {
      cin >> arr[i];
      mp[arr[i]]++;
     if(mp[arr[i]+1]==0)ans++;
     
    }
    //ll ans = cnt - ant + 1;
    cout << ans<<endl;
}




int main()
{
   IOS;
   ll t;
    t=1;
   // scanf("%d",&t);
    cin>>t;
    ca=1;
    while(t--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}

Invoker

思路:

        你和我说这是简单dp?????????

由于按键可以保留,那么尽量让本次的按键对下次技能的按键保留的最多。
但是由于技能之间的按键顺序可以任意,所以我们dp按键组合。
因为一个技能有三个键,所以可以产生六种排序方式(完全相同的也算上)。
dp[i][j]表示第i个技能使用第j种排序方式的按键数,这样我们可以得出方程dp[i][j]=min(dp[i][j],dp[i-1][k]+(第i-1个技能使用第j种排序方式和第i个技能使用第k种排序方式的差值))。
 


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
const ll hash_num = 3e9+9;

char d[10][6][4]={  //补全排序
 {"QQQ","QQQ","QQQ","QQQ","QQQ","QQQ"},
 {"QQW","QWQ","WQQ","WQQ","WQQ","WQQ"},
 {"QQE","QEQ","EQQ","EQQ","EQQ","EQQ"},
 {"WWW","WWW","WWW","WWW","WWW","WWW"},
 {"QWW","WQW","WWQ","WWQ","WWQ","WWQ"},
 {"WWE","WEW","EWW","EWW","EWW","EWW"},
 {"EEE","EEE","EEE","EEE","EEE","EEE"},
 {"QEE","EQE","EEQ","EEQ","EEQ","EEQ"},
 {"WEE","EWE","EEW","EEW","EEW","EEW"},
 {"QWE","QEW","EQW","EWQ","WEQ","WQE"},
};
map<char,ll>m;
char ch[100010];
ll p[1000100],dp[1000100][6];
ll check(ll a,ll b,ll x,ll y){
	if(d[a][x][0]==d[b][y][0]&&d[a][x][1]==d[b][y][1]&&d[a][x][2]==d[b][y][2])
		return 0;
	else if(d[a][x][1]==d[b][y][0]&&d[a][x][2]==d[b][y][1])	
		return 1;
	else if(d[a][x][2]==d[b][y][0])
		return 2;
	else 
		return 3;
}
int main()
{
	m['X']=0;m['V']=1;m['G']=2;
	m['C']=3;m['X']=4;m['Z']=5;
	m['T']=6;m['F']=7;m['D']=8;m['B']=9;
	ll ans=0,sum=0;
	while(cin>>ch){
		int l=strlen(ch);
		ans=0,sum=0;
		p[sum++]=m[ch[0]];
		for(int i=1;i<l;i++){
			if(m[ch[i]]==p[sum-1]) 
				ans++;
			else
				p[sum++]=m[ch[i]];
		}
		ans+=sum; 
		memset(dp,0x3f,sizeof(dp));
		dp[0][0]=3;dp[0][1]=3;dp[0][2]=3;dp[0][3]=3;dp[0][4]=3;dp[0][5]=3;
		for(int i=1;i<sum;i++){
			for(int j=0;j<6;j++){
				for(int k=0;k<6;k++){
					dp[i][j]=min(dp[i][j],dp[i-1][k]+check(p[i-1],p[i],k,j));
				}
			}
		}
		ll mi=dp[sum-1][0];
		for(int i=0;i<6;i++)
			mi=min(mi,dp[sum-1][i]);
		cout<<ans+mi<<endl;;
	}
	
    return 0;
}

 MUV LUV EXTRA

 、

思路: 

先反转一下,对于每一个位置,我们要求出这个位置开始的最短循环节。这个 K M P KMP KMP一下即可。

例如 a b a a b a a b abaabaab abaabaab, f a i l [ 8 ] fail[8] fail[8](最后一位后面)指向 6 6 6( a b a a b abaab abaab后面),那么说明这两段相同。这个又说明 a b , a b a a b ab,abaab ab,abaab也匹配,所以 f a i l fail fail跳跃的数量就是最短的可行循环节。
 



#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
const ll hash_num = 3e9+9;
ll n,m,ca, k, p;
 ll arr[N],brr[N],crr[N];
 int h[N],ne[N],e[N],w[N],idx;

//string s;
char s[N];
char x[N];
ll ant[N];

void KMP(){
    ant[0]=-1,ant[1]=0;
    ll len=strlen(x);
    ll i=1,j=0;
    while(i<len&&j<len){
        if(j==-1||x[i]==x[j])ant[++i]=++j;
        else j=ant[j];
    }
}


void solve()
{	
  scanf("%lld %lld%s",&n,&m,s);
 // scanf("%s",s);
   ll tlen=strlen(s);
        ll len=0;
        per(i,tlen-1,0){
            if(s[i]=='.')break;
            x[len++]=s[i];
        }
        KMP();
        ll ans=n-m;
        rep(i,1,len-1){
            ans=max(ans,n*(i+1)-m*(i+1-ant[i+1]));
        }
  printf("%lld\n",ans);

}




int main()
{
   //IOS;
   ll _;
    _=1;
   // scanf("%d",&t);
    //cin>>_;
    ca=1;
    while(_--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}

 Forest Program

 思路:

        一个博弈论,也就是看奇偶路径情况



#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
const ll hash_num = 3e9+9;
ll n,m,ca;
 ll arr[N],brr[N],crr[N];
//  int h[N],ne[N],e[N],w[N],idx;

void solve()
{	
    cin >> n;
    vector<ll>ve[n+1],vve[n+1];
    rep(i,1,n)
    {
     arr[i]=0,brr[i]=0;
    }
    rep(i,2,n)
    {
      cin >> arr[i];
      brr[arr[i]]++;
    }
    ll flag=0;
    rep(i,1,n)
    {
      if(brr[i]==0)
      {
        ll ant=i,res=0;
        while(brr[ant]<2)
        {
          res++;
          if(ant==1)break;
           ant=arr[ant];
        }
        if(res&1){flag=1;break;}
      }
     
    }
    if(flag)
    {
      cout<<"Takeru"<<endl;
    }else{
      cout<<"Meiya"<<endl;
    }
}




int main()
{
   IOS;
   ll _;
    _=1;
   // scanf("%d",&t);
    cin>>_;
    ca=1;
    while(_--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}

Angle Beats

 思路:
        运用离线处理的方法,要不然会t,直角三角形去考虑斜率的问题,斜率相乘-1都是垂直



#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
const ll hash_num = 3e9+9;
ll n,m,ca;
 ll arr[3000];
//  int h[N],ne[N],e[N],w[N],idx;

unordered_map<ll,ll>mp;
ll Hash(ll x, ll y)
{
    // if(x==0)y=abs(y);
    // return x*233333333+y;
    return x*hash_num+y;
}
 

ll gcdd(ll a, ll b)
{
      // while(b^=a^=b^=a%=b);    
      // return a;
      if(b==0)return a;
      return gcdd(b,a%b);
}

struct noda
{
  /* data */
  ll x,y;
}noda[3000],q[3000];



void solve()
{	
  cin >> n >> m;
  rep(i,1,n)cin >> noda[i].x >> noda[i].y;
  rep(i,1,m)cin >> q[i].x >> q[i].y;

  rep(i,1,m)
  {
    mp.clear();
    rep(j,1,n)
    {
      ll xx = q[i].x - noda[j].x;
      ll yy = q[i].y - noda[j].y;
      ll ant = gcdd(xx,yy);
      xx /= ant,yy /= ant;
      ll num = Hash(xx,yy);
      mp[num]++;
    }
    rep(j,1,n)
    {
      ll xx = q[i].x - noda[j].x;
      ll yy = q[i].y - noda[j].y;
      ll ant = gcdd(xx,yy);
      xx /= ant,yy /= ant;
      arr[i] += mp[Hash(yy,-xx)];
      arr[i] += mp[Hash(-yy,xx)];
    }
    arr[i] /= 2;
  }

    rep(i,1,n)
    {
      mp.clear();
      rep(j,1,n)
      {
        if(i != j)
        {
          ll xx = noda[i].x-noda[j].x;
          ll yy = noda[i].y-noda[j].y;
          ll ant = gcdd(xx,yy);
          xx/=ant,yy/=ant;
          ll num = Hash(xx,yy);
          mp[num]++;
        }
      }
      rep(j,1,m)
      {
          ll xx = noda[i].x-q[j].x;
          ll yy = noda[i].y-q[j].y;
          ll ant = gcdd(xx,yy);
          xx/=ant,yy/=ant;
          arr[j]+=mp[Hash(yy,-xx)];
           arr[j]+=mp[Hash(-yy,xx)];
      }
    }
  rep(i,1,m)
  {
    cout<<arr[i]<<endl;
  }
}




int main()
{
   IOS;
   ll t;
    t=1;
   // scanf("%d",&t);
   // cin>>t;
    ca=1;
    while(t--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}

Catch You Catch Me

 思路:

思维题,只要在1节点下面的节点等着就行了



#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
 ll  INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
//   return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 1e6+ 10;
const ll mod =1000000007;
ll n,m,ca;
 ll arr[N],brr[N],crr[N];
//  int h[N],ne[N],e[N],w[N],idx;


// ll get_len(ll x1,ll y1,ll x2 ,ll y2)
// {
//   return abs(x1-x2)+abs(y1-y2);
// }
vector<ll>ve[N];
ll ant ,cnt,ans;
ll dep[N];
ll depth(ll ant,ll cnt)
{
  
  dep[ant] = dep[cnt] + 1;
  ll res = dep[ant];
    for (auto it : ve[ant])
    {
        if (it != cnt)
        {
          ll d = depth(it,ant);
          res = max(res, d);
          if (ant == 1) ans += d - 1;
        
        }
    }
    return res;
}


void solve()
{	
  
  cin >> n;
  rep(i,1,n-1)
  {
    ll x,y;
    cin >> x >> y;
    ve[x].push_back(y);
    ve[y].push_back(x);
  }
  // ll ans = 0;
  // ans += ve[1].size();
  // //cout << ans<<endl;
  // for(int i =0;i< ve[1].size();i++)
  // {
  //   ant =0,res =0;
  //   depth(ve[1][i],res);
  //   ans += ant;
  // }
  depth(1,0);
  cout << ans;
  
}




int main()
{
   IOS;
   ll t;
    t=1;
   // scanf("%d",&t);
    //cin>>t;
    ca=1;
    while(t--)
    {
      solve(); 
      ca++;
    }    
    return 0;
}

总结就是:我还是太菜了啊

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/748934.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

JavaFX 基础

1.JavaFX应用的程序基本结构 窗口(stage)&#xff1a;窗口里面可以设置场景&#xff0c;但是一次只能显示一个场景。 场景(scene)&#xff1a;场景可以添加UI组件图的树形结构。 根节点(parent)&#xff1a;根节点设置为一个布局&#xff0c;放置不同的节点(组件)。可以在根节…

备战秋招 | 笔试强训2

目录 一、选择题 二、编程题 三、选择题题解 四、编程题题解 一、选择题 1、使用printf函数打印一个double类型的数据&#xff0c;要求&#xff1a;输出为10进制&#xff0c;输出左对齐30个字符&#xff0c;4位精度。以下哪个选项是正确的&#xff1f; A. %-30.4e B. %4.…

白皮书案例解读|数字孪生与港口的结合会碰撞出什么样的火花呢?

以下案例来自于《数字孪生世界白皮书&#xff08;2023版&#xff09;》 领取方式&#xff1a;公众号「EasyV数字孪生」后台回复「白皮书」即可领取&#xff01; 嗨&#xff0c;我又出现啦&#xff5e;今天想和大家聊聊关于港口场景数字孪生技术的应用&#xff0c;欢迎大家踊跃…

Linux登录时,下游回显非常慢

目录 问题现象 原因分析 解决方法 源码等资料获取方法 问题现象 登录linux时&#xff0c;远程连接正常&#xff0c;[root...]回显非常慢&#xff0c;在执行脚本时&#xff0c;很容易导致命令下发错乱 原因分析 家目录下的.bash_history文件太大&#xff0c;导致每次登陆时读…

magento2 二次开发如何自定义theme

1.在app\design\frontend下创建自定义Theme文件夹&#xff0c;格式为Vendor/ThemeName&#xff0c;比如TestCompany/test 2.在TestCompany/test目录下创建文件夹和文件如下&#xff1a; etc 非必须创建 在此目录下添加view.xml&#xff0c;内容如下&#xff1a; view.xml可定…

Occupy the Cities - 思维+二分

分析&#xff1a; 分析每一个0的位置&#xff0c;记录每一个0距离两侧的1的最近距离&#xff0c;每一个1要么向左扩展要么向右扩展&#xff0c;可以将扩展过的1标记&#xff0c;如果需要向另一侧扩展&#xff0c;那么必须满足距离另一侧的0的距离加1小于等于时间&#xff0c;比…

网络安全行业的那些岗位

网络安全行业&#xff0c;正在蓬勃发展&#xff0c;想要找网络安全岗位的&#xff0c;可以参考这篇文章 一、网络安全岗位 1、需要网络安全人员的企业 有三种企业招聘网络安全人员&#xff1a;乙方企业、甲方企业、国有企业 乙方企业是专门从事网络安全行业的企业&#xff0c…

用Arthas快速定位线上JVM问题!

Arthas分析FullGC问题定位 对于FullGC那一定不会陌生,一般来说会采用横切FullGC前置拦截(-XX:+HeapDumpBeforeFullGC)和后置拦截(-XX:+HeapDumpAfterFullGC),导出FullGC发生前后的heap dump文件,以便于我们进行FullGC原因的分析和定位。 推测分析问题之FullGC的频率过高…

SpringBoot2+Vue2实战(十八)修改密码

一、修改密码&#xff1a; Header.vue <el-dropdown-item style"font-size: 14px; padding: 5px 0"><router-link to"/password" style"text-decoration: none">修改密码</router-link></el-dropdown-item> router/i…

tensorrt8.5.2安装,并解决CMAKE找不到tensorrt问题

ubuntu20.04、cuda11.1、cudnn8.0.5&#xff08;后续要更新到8.6.0&#xff09; tensorrt下载网址&#xff1a;NVIDIA TensorRT 8.x Download | NVIDIA Developer 选择自己合适的cuda安装 下载的时候可以使用wget wget https://developer.download.nvidia.com/compute/machin…

【springboot】RestTemplate序列化RedisSerializer到底该选哪个

RedisTemplate是Spring Data Redis提供给用户的最高级的抽象客户端&#xff0c;用户可直接通过RedisTemplate对Redis进行多种操作。 在项目中使用需要引入如下依赖&#xff1a; <dependency><groupId>org.springframework.boot</groupId><artifactId>…

ScrollRect滚动区域Content列表项数据钳制取值问题

问题 如下图示例&#xff0c;是一个选择日期、时间的日历控件&#xff0c;右侧小时与分钟的部分是两个Scroll Rect滚动区域组件&#xff0c;滚动到中间高亮部分表示选择&#xff0c;那么如何让滚动停止在合适的位置&#xff1f;避免出现如图所示的停在两个数据项中间的情况。 …

Slam十四讲之第一讲和第二讲,实践编程基础

目录 1.镜像寻找①方法1&#xff1a;百度网盘下载②方法2&#xff1a;在开源镜像网站上下载&#xff0c;③方法3&#xff1a;直接在Ubuntu官网下载 2 在VMware中创建虚拟机并安装Ubuntu18.043 安装VMware Tools4 初始系统中&#xff0c;部分软件的安装4.1 gcc 安装4.2 g安装4.3…

Word 插件实现读取excel自动填写

日常工作中碰到需要将EXCEL的对应数据记录填写到word文档对应的位置&#xff0c;人工操作的方式是&#xff1a; 打开exel表—>查找对应报告号的行—>逐列复制excel表列单元格内容到WORD对应的位置&#xff08;如下图标注所示&#xff09; 这种方法耗时且容易出错。实际上…

vcomp140.dll丢失怎样修复?多种方法教你修复

vcomp140.dll丢失算是一个比较常见的异常事件&#xff0c;在使用电脑的时候&#xff0c;有时候弹窗出现由于找不到vcomp140.dll&#xff0c;无法继续执行代码等&#xff0c;这种都是属于vcomp140.dll文件丢失&#xff0c;今天我们主要针对这个情况来给大家说说vcomp140.dll丢失…

自动化测试工具大盘点

本系列文章我们将带大家一起了解一下互联网大厂中通科技的自动化测试平台的搭建历程&#xff0c;从以下四个方面展开介绍&#xff1a;为什么要做这样一个统一的自动化测试平台&#xff1f;是如何做到统一的&#xff1f;平台上线后的收益&#xff0c;最后一部分会给大家分享一下…

CSDN 周赛 62 期

CSDN 周赛 62 期 参赛体验选择题1234编程题1、题目名称:覆盖面积2、题目名称:机器猫参赛体验 这次没有出填空题,好评。 选择题四个,基本上,对数据库比较熟悉的人,应该都可以全部答对的。 编程题两个,嗯。。。。就是上周偷偷摸摸更新出来的四个题目之二。还以为不会出…

levelx norFlash

levelx 文章目录 OverviewQuoteBriefDefinitionTheory 实现原理1.初始化流程2.写操作3.读操作4.回收函数 Overview 实现了flash的均衡摩擦&#xff0c;有针对nor 和 nand的接口 配合azure RTOS 以及xfile比较合适&#xff0c;单独使用不是很友好 Quote https://learn.micro…

C# Sdcb.Paddle2Onnx Paddle模型通过C#转换为ONNX模型

https://github.com/sdcb/PaddleSharp/blob/feature/2.5/docs/paddle2onnx.md 效果 项目 代码 using Sdcb.Paddle2Onnx; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing…

相对绝对定位父元素不设置宽度,根据子元素撑开(white-space: nowrap;)

要做一个如下的弹窗&#xff0c;很简单。但是当要切换成多语言或者数据是动态的话&#xff08;title可能会很长&#xff09;&#xff0c;那么弹窗固定宽度就不适用了。 有可能会出现下图的情况 也有可能出现下面的情况&#xff0c;文字被换行了&#xff08;有时候这种情况也是…