2021牛客寒假算法基础集训营4，签到题AGJ

A. 九峰与签到题

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
struct node{int ac=0, unac=0;}a[50];
int vis[50];
int main(){
int m, n;  cin>>m>>n;
for(int i = 1; i <= m; i++){
int x; string op;  cin>>x>>op;
if(op=="AC")a[x].ac++;else a[x].unac++;
if(a[x].ac+a[x].unac==1 && a[x].unac==1)vis[x] = 1;
if(a[x].ac*1.0/(a[x].ac+a[x].unac) < 0.5)vis[x] = 1;
}
vector<int>ans;
for(int i = 1; i <= n; i++)
if(vis[i]==0 && a[i].ac+a[i].unac!=0)ans.push_back(i);
if(ans.size()==0)cout<<"-1";
else{
for(int i = 0; i < ans.size(); i++)
cout<<ans[i]<<" ";
}
return 0;
}



G. 九峰与蛇形填数

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 4e3+10;
int a[maxn][maxn], x[maxn], y[maxn], k[maxn];
int main(){
ios::sync_with_stdio(false);
int n, m;  cin>>n>>m;
int x1 = maxn, x2 = 1, y1 = maxn, y2 = 1;
for(int i = 1; i <= m; i++){
cin>>x[i]>>y[i]>>k[i];
x1 = min(x1,x[i]);
x2 = max(x2,x[i]+k[i]-1);
y1 = min(y1,y[i]);
y2 = max(y2,y[i]+k[i]-1);
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
for(int z = m; z >= 1; z--){
if(i<x1||i>x2||j<y1||j>y2)break;
if(i>=x[z] && i<=x[z]+k[z]-1 && j>=y[z]&&j<=y[z]+k[z]-1){
a[i][j] = (i-x[z])*k[z];
if((i-x[z])%2==1)a[i][j]+=y[z]+k[z]-1-j+1;
else a[i][j]+=j-y[z]+1;
break;
}
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
cout<<a[i][j]<<" ";
cout<<"\n";
}
return 0;
}



J. 邬澄瑶的公约数

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e4+10;
const int mod = 1e9+7;
int a[maxn], b[maxn];//,c[maxn];
bitset<maxn>p;
LL pows(LL a, LL b, LL m) {
a %= m;
LL res = 1;
while(b>0){
if(b&1)res=res*a%m;
a = a*a%m;
b >>= 1;
}
return res%m;
}
int main(){
int n; cin>>n;
int _max = 0;
for(int i = 1; i <= n; i++){cin>>a[i]; _max = max(_max,a[i]);}
for(int i = 1; i <= n; i++)cin>>b[i];

LL ans = 1, c;
for(int i = 2; i <= _max; i++){
if(p[i])continue;
for(int j = 2*i; j <= _max; j+=i){
p[j] = 1;
}
c = mod;
for(int j = 1; j <= n; j++){
if(a[j]%i!=0){c = 0; break;}
else{
int t = a[j], tt = 0;
while(t>0 && t%i==0){t/=i;tt++;}
if(tt*b[j]!=1)c = min(c,(LL)tt*b[j]);
else c = 1;
//cout<<i<<" "<<a[j]<<" "<<b[j]<<"\n";
}
}
//cout<<i<<" "<<c<<"\n";
if(c!=0 && c!=mod)ans = ans*pows(i,c,mod)%mod;
}
cout<<ans<<"\n";
return 0;
}



02-19 1527
04-07 411
02-12 124
02-11 1891
02-12 3364