牛客IOI周赛22-普及组
菜哭了
A
求找一个点到所有点的距离相等。
因为横纵坐标为整数且1<=n<=200,暴力枚举即可
#include
using namespace std;
const int maxn=5e5+5;
const int mod=998244353;
#define ll long long
int n,a[50000],b[50000];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
}
for(int i=1;i<=200;i++){
for(int j=1;j<=200;j++){
int k=2;
int dis=(b[1]-j)*(b[1]-j)+(a[1]-i)*(a[1]-i);
for(;k<=n;k++){
int s=(b[k]-j)*(b[k]-j)+(a[k]-i)*(a[k]-i);
if(s!=dis)break;
}
if(k==n+1){
printf("%d %d\n",i,j);
return 0;
}
}
}
printf("War is cruel.\n");
return 0;
}
B
题意:n个数,求最少的轮回把数取完,规则是:当前取的数为现序列最大
方法一:队列模拟,(60分 O(n^2))
方法二:标答:把每个数有两个权值,一个是在原序列的位置1,一个是在按照从大到小排列后的位置2。对于已经排好的序列,如果,当前数的位置1<后一个数的位置1,ans++
#include
using namespace std;
const int maxn=1e6+5;
int n,a[maxn],dp[maxn];
bool cmp(int x,int y){
return x>y;
}
int main(){
int ans=1;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
dp[a[i]]=i;
}
sort(a+1,a+1+n,cmp);
for(int i=2;i<=n;i++){
if(dp[a[i]]<dp[a[i-1]])ans++;
}
printf("%d\n",ans);
}
C
#include
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=77797;
int n,a[maxn],dp[maxn];
int main(){
ll ans=1;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
ll he=(pow(26,a[i])-1)/25*26-i+1;
if(he<=0){
printf("-1\n");
return 0;
}
he%=mod;
ans=(ans*he)%mod;
}
printf("%lld\n",ans);
}
D
最小生成树板子
#include
#include
#include
using namespace std;
typedef long long ll;
int read(){
int x=0,pos=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') pos=0;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return pos?x:-x;
}
struct node{
int v,nex;
ll w;
}edge[4000001];
struct pt{
int po,d;
bool operator < (const pt &a) const{
return d>a.d;
}
};
int top,head[1000001];
void add(int u,int v,ll w){
edge[++top].v=v;
edge[top].nex=head[u];
edge[top].w=w;
head[u]=top;
}
int n,m;
queue<pt>q;
int vis[1000001];
int main(){
n=read(),m=read();
for(int i=1;i<=m;i++){
ll u=read(),v=read(),w=read();
add(u,v,w);
add(v,u,w);
}
ll ans=0;
priority_queue<pt>q;
pt fi;
fi.po=1;
fi.d=0;
q.push(fi);
int cnt=0;
while(!q.empty()){
pt now=q.top();q.pop();
if(vis[now.po]) continue;
cnt++;
vis[now.po]=1;
ans+=now.d;
for(int i=head[now.po];i;i=edge[i].nex){
int v=edge[i].v;
if(!vis[v]){
pt ne;
ne.d=edge[i].w;
ne.po=v;
q.push(ne);
}
}
}
printf("%lld",ans*2);
return 0;
}