L2-016 愿天下有情人都是失散多年的兄妹
这题一开始我没有标注爸爸妈妈是男的是女的直接卡了半天
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=4002;
//unordered_map<LL,LL> um[N];
//priority_queue<LL,vector<LL>,greater<LL>> pq;
vector<LL> v[N];
struct node
{
char sex;
}people[N];
LL vis[N],flag=0;
void dfs(LL x,LL depth)
{
if(depth>=5) return ;
for(int i=0;i<v[x].size();i++)
{
if(vis[v[x][i]]==0)
{
vis[v[x][i]]=1;
dfs(v[x][i],depth+1);
}
else
{
flag=1;
return ;
}
}
}
int main()
{
//cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n;
cin>>n;
for(int i=1;i<=n;i++)
{
LL id,fa,ma;
char sex;
cin>>id>>people[id].sex>>fa>>ma;
if(fa!=-1)
{
v[id].push_back(fa);
people[fa].sex='M';
}
if(ma!=-1)
{
v[id].push_back(ma);
people[ma].sex='F';
}
}
LL q;
cin>>q;
while(q--)
{
LL a,b;
cin>>a>>b;
if(people[a].sex==people[b].sex) cout<<"Never Mind"<<endl;
else
{
flag=0;
memset(vis,0,sizeof vis);
dfs(a,1);
dfs(b,1);
if(flag==1) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
}
}
return 0;
}
L2-017 人以群分
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=4002;
//unordered_map<LL,LL> um[N];
//priority_queue<LL,vector<LL>,greater<LL>> pq;
LL a[N];
int main()
{
//cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+1+n);
LL avg=n/2;
LL sum1=0,sum2=0;
if(n%2==0)
{
for(int i=1;i<=n/2;i++)
sum1+=a[i];
for(int i=n/2+1;i<=n;i++)
sum2+=a[i];
}
else
{
for(int i=1;i<=n/2;i++)
{
sum1+=a[i];
sum2+=a[n-i+1];
}
// cout<<sum1<<" "<<sum2<<endl;
LL num1=sum1+a[n/2+1];
LL num2=sum2;
sum2+=a[n/2+1];
//cout<<num1<<" "<<num2<<" "<<sum1<<" "<<sum2<<endl;
if(abs(num1-num2)>=abs(sum1-sum2)) avg=n/2+1;
}
cout<<"Outgoing #: "<<n-avg<<endl;
cout<<"Introverted #: "<<avg<<endl;
cout<<"Diff = "<<abs(sum1-sum2)<<endl;
}
return 0;
}
L2-018 多项式A除以B
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=4002;
//unordered_map<LL,LL> um[N];
//priority_queue<LL,vector<LL>,greater<LL>> pq;
double a[N],b[N],c[N];
LL n,m,x,maxn1=-MAXN,maxn2=-MAXN;
void solve(double f[],LL idx)
{
LL res=0;
for(LL i=0;i<=idx;i++)
if(abs(f[i])>=0.05) res++;
cout<<res;
if(res==0) cout<<" 0 0.0";
for(LL i=idx;i>=0;i--)
if(abs(f[i])>=0.05)
printf(" %d %.1lf",i,f[i]);
}
int main()
{
//cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
cin>>n;
for(LL i=0;i<n;i++)
{
cin>>x>>a[x];
maxn1=max(maxn1,x);
}
cin>>m;
for(LL i=0;i<m;i++)
{
cin>>x>>b[x];
maxn2=max(maxn2,x);
}
LL maxn3=maxn1-maxn2;
while(maxn1-maxn2>=0)
{
double p=a[maxn1]/b[maxn2];
c[maxn1-maxn2]=p;
for(LL i=maxn1,j=maxn2;i>=0&&j>=0;i--,j--)
{
a[i]-=p*b[j];
}
while(!a[maxn1])
{
maxn1--;
}
}
solve(c,maxn3);
cout<<endl;
solve(a,maxn1);
}
return 0;
}
L2-019 悄悄关注
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=4002;
//unordered_map<LL,LL> um[N];
//priority_queue<LL,vector<LL>,greater<LL>> pq;
string s[N];
struct node
{
string c;
LL x;
LL flag=0;
}a[N];
bool cmp(node l,node r)
{
if(l.c!=r.c) return l.c<r.c;
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n;
cin>>n;
map<string,LL> mp;
for(int i=1;i<=n;i++)
{
cin>>s[i];
mp[s[i]]++;
}
LL q;
cin>>q;
LL sum=0;
for(int i=1;i<=q;i++)
{
cin>>a[i].c>>a[i].x;
sum+=a[i].x;
if(mp[a[i].c]==0) a[i].flag=1;
}
LL avg=sum/q;
sort(a+1,a+1+q,cmp);
bool flag=false;
for(int i=1;i<=q;i++)
{
if(a[i].flag==1&&a[i].x>avg)
{
cout<<a[i].c<<endl;
flag=true;
}
}
if(flag==false) cout<<"Bing Mei You"<<endl;
}
return 0;
}
L2-020 功夫传人
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=4002;
//unordered_map<LL,LL> um[N];
//priority_queue<LL,vector<LL>,greater<LL>> pq;
LL n;
double z,r;
vector<LL> v[N];
struct node
{
double bei;
double gl;
}a[N];
double sum=0;
void dfs(LL idx,LL last)
{
if(idx!=0) a[idx].gl=a[last].gl*(double)(1-r/100.00);
if(v[idx].size()==0)
{
a[idx].gl*=a[idx].bei;
sum+=a[idx].gl;
return ;
}
for(int i=0;i<v[idx].size();i++)
{
dfs(v[idx][i],idx);
}
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
cin>>n>>z>>r;
a[0].gl=z;
for(int i=0;i<n;i++)
{
LL op;
cin>>op;
if(op==0)
{
double x;
cin>>x;
a[i].bei=x;
}
else
{
while(op--)
{
double x;
cin>>x;
v[i].push_back(x);
}
}
}
dfs(0,-1);
cout<<(int)sum<<endl;
}
return 0;
}
标签:练习题,typedef,const,--,LL,cin,int,L2,016
From: https://www.cnblogs.com/Vivian-0918/p/17020213.html