2021牛客寒假算法基础集训营4,签到题AGJ
【摘要】
A. 九峰与签到题
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
struct node{int ...
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;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
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;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
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;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。
原文链接:gwj1314.blog.csdn.net/article/details/113869924
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)