How to ak 【LGR-145-Div.4】洛谷入门赛 #14?.
A 数字判断
题面
给你三个数 \(a,b,c\),给予你四个条件:
1.\(a+b+c \leq 100\)。
2.\(b\) 是 \(5\) 的整数倍。
3.\(c\) 是 \(7\) 的整数倍。
4.\(a-b > b-c\)。
如果满足上述条件就输出 Yes,否则输出 No。
做法
if 判断即可。
代码
#include<bits/stdc++.h>
using namespace std;
signed main(){
int a,b,c;
cin>>a>>b>>c;
if(a+b+c<=100&&b%5==0&&c%7==0&&a-b>b-c)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
B 团伙首领
题面
有 \(n\) 个人,每个人都有自己的首领,问一共有多少的首领。
做法
for 循环枚举每个人,让每个人的 f[a[i]=1,最后看有多少个人的值为 1。
代码
#include<bits/stdc++.h>
using namespace std;
int a[1000006];
int f[1000006];
signed main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
f[a[i]]=1;
}
int ans=0;
for(int i=1;i<=n;i++)
if(f[i])ans++;
cout<<ans<<endl;
return 0;
}
C 枚举结构
题面
给你两个 char 类型的变量 x 和 z,以及两个整数 y 和 w。
给你三个条件:
1.x 和 z 均为小写字母。
2.x 与 z 相同。
3.y 与 w 均为整数(这条保证成立)。
如果满足上述三个条件,就为合法,否则不合法。
输出共两行。
- 第一行
如果合法就输出valid,不合法就输出Invalid。 - 第二行
如果不合法就输出-1。
如果合法:
- 如果 \(y<=w\),输出 \(w-y+1\)。
- 否则输出 \(y-w+1\)。
做法
还是简单的 if 判断。
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define re register
#define lll __int128
#define gc getchar
#define pt putchar
#define int long long
using namespace std;
const int SIZE=1<<14;
inline int read(){
re int x=0;re bool f=0;static char ch=gc();
while(!(ch>=48&&ch<=57)&&ch!=EOF){if(ch=='-')f=1;ch=gc();}
while(ch>=48&&ch<=57){x*=10;x+=(ch-48);ch=gc();}
if(f)return -x;else return x;
}
void print(int x){
char st[105];re int top=0;
if(x==0)putchar('0');if(x<0)putchar('-');
while(x){if(x>0)st[++top]=x%10+48;else st[++top]=-(x%10)+48;x/=10;}
while(top)putchar(st[top--]);
}
void println(int x){
print(x);putchar('\n');
}
void printsp(int x){
print(x);putchar(' ');
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
char x,z;
int y,w;
cin>>x;
cin>>y;
cin>>z;
cin>>w;
if('a'<=x&&x<='z'&&'a'<=z&&z<='z'&&x==z){
cout<<"valid"<<endl;
if(y<=w){
cout<<w-y+1<<endl;
}
else cout<<y-w+1<<endl;
}
else {
cout<<"Invalid"<<endl;
cout<<-1<<endl;
}
return 0;
}
D 塔台超频
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define re register
#define lll __int128
#define gc getchar
#define pt putchar
#define int long long
using namespace std;
const int SIZE=1<<14;
inline int read(){
re int x=0;re bool f=0;static char ch=gc();
while(!(ch>=48&&ch<=57)&&ch!=EOF){if(ch=='-')f=1;ch=gc();}
while(ch>=48&&ch<=57){x*=10;x+=(ch-48);ch=gc();}
if(f)return -x;else return x;
}
void print(int x){
char st[105];re int top=0;
if(x==0)putchar('0');if(x<0)putchar('-');
while(x){if(x>0)st[++top]=x%10+48;else st[++top]=-(x%10)+48;x/=10;}
while(top)putchar(st[top--]);
}
void println(int x){
print(x);putchar('\n');
}
void printsp(int x){
print(x);putchar(' ');
}
int a[500005],b[500005];
int n,maxn;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i];
for(int i=2;i<=n;i++){
int x=a[i]-a[i-1];
if(x<=b[i-1])continue;
else maxn=max(maxn,x-b[i-1]);
}
cout<<maxn<<endl;
return 0;
}
E 署前街少年
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define re register
#define lll __int128
#define gc getchar
#define pt putchar
#define int long long
using namespace std;
const int SIZE=1<<14;
inline int read(){
re int x=0;re bool f=0;static char ch=gc();
while(!(ch>=48&&ch<=57)&&ch!=EOF){if(ch=='-')f=1;ch=gc();}
while(ch>=48&&ch<=57){x*=10;x+=(ch-48);ch=gc();}
if(f)return -x;else return x;
}
void print(int x){
char st[105];re int top=0;
if(x==0)putchar('0');if(x<0)putchar('-');
while(x){if(x>0)st[++top]=x%10+48;else st[++top]=-(x%10)+48;x/=10;}
while(top)putchar(st[top--]);
}
void println(int x){
print(x);putchar('\n');
}
void printsp(int x){
print(x);putchar(' ');
}
int a[5000006];
int f[5000006];
int p[5000006];
int ph[50000006];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;
cin>>n>>k;
for(int i=1;i<=2*n;i++)
cin>>a[i];
for(int i=1;i<=2*n;i++){
if(i%2==0)f[i]=0;
else f[i]=1;
}
for(int i=1;i<=2*n;i++){
p[i]=i%k;
}
for(int i=1;i<=2*n;i++){
ph[p[i]]+=a[i];
}
for(int i=1;i<=2*n;i++)
if(i%2==1)a[i]=ph[p[i]]%i;
for(int i=1;i<=2*n;i++)
cout<<a[i]<<' ';
return 0;
}
F 扶苏和串
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define re register
#define lll __int128
#define gc getchar
#define pt putchar
#define int long long
using namespace std;
const int SIZE=1<<14;
inline int read(){
re int x=0;re bool f=0;static char ch=gc();
while(!(ch>=48&&ch<=57)&&ch!=EOF){if(ch=='-')f=1;ch=gc();}
while(ch>=48&&ch<=57){x*=10;x+=(ch-48);ch=gc();}
if(f)return -x;else return x;
}
void print(int x){
char st[105];re int top=0;
if(x==0)putchar('0');if(x<0)putchar('-');
while(x){if(x>0)st[++top]=x%10+48;else st[++top]=-(x%10)+48;x/=10;}
while(top)putchar(st[top--]);
}
void println(int x){
print(x);putchar('\n');
}
void printsp(int x){
print(x);putchar(' ');
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s,now,ans;
cin>>s;
ans=s;
int len=s.length();
for(int i=0;i<len;i++)
for(int j=i;j<len;j++){
now=s;
for(int k=0;k<=(j-i)/2;k++)
swap(now[i+k],now[j-k]);
if(now<ans)
ans=now;
}
cout<<ans<<endl;
return 0;
}
G Three-View Projection
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define re register
#define lll __int128
#define gc getchar
#define pt putchar
#define int long long
using namespace std;
const int SIZE=1<<14;
inline int read(){
re int x=0;re bool f=0;static char ch=gc();
while(!(ch>=48&&ch<=57)&&ch!=EOF){if(ch=='-')f=1;ch=gc();}
while(ch>=48&&ch<=57){x*=10;x+=(ch-48);ch=gc();}
if(f)return -x;else return x;
}
void print(int x){
char st[105];re int top=0;
if(x==0)putchar('0');if(x<0)putchar('-');
while(x){if(x>0)st[++top]=x%10+48;else st[++top]=-(x%10)+48;x/=10;}
while(top)putchar(st[top--]);
}
void println(int x){
print(x);putchar('\n');
}
void printsp(int x){
print(x);putchar(' ');
}
int a[1005][1005];
int zheng[1005];
int zuo[1005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]==1){
zheng[i]=1;
zuo[j]=1;
}
}
for(int i=1;i<=n;i++)
cout<<zheng[i]<<' ';
cout<<endl;
for(int i=m;i>=1;i--)
cout<<zuo[i]<<' ';
cout<<endl;
for(int i=m;i>=1;i--){
for(int j=1;j<=n;j++)
cout<<a[j][i]<<' ';
cout<<endl;
}
return 0;
}
H 魔法少女扶苏
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define re register
#define lll __int128
#define gc getchar
#define pt putchar
#define int long long
using namespace std;
const int SIZE=1<<14;
inline int read(){
re int x=0;re bool f=0;static char ch=gc();
while(!(ch>=48&&ch<=57)&&ch!=EOF){if(ch=='-')f=1;ch=gc();}
while(ch>=48&&ch<=57){x*=10;x+=(ch-48);ch=gc();}
if(f)return -x;else return x;
}
void print(int x){
char st[105];re int top=0;
if(x==0)putchar('0');if(x<0)putchar('-');
while(x){if(x>0)st[++top]=x%10+48;else st[++top]=-(x%10)+48;x/=10;}
while(top)putchar(st[top--]);
}
void println(int x){
print(x);putchar('\n');
}
void printsp(int x){
print(x);putchar(' ');
}
int a[1005][1005];
int n,m,k;
bool get_ans(int num){
int ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
int sum=0;
for(int x=1;x<=n;x++)
sum+=a[x][j]-num;
for(int y=1;y<=m;y++)
sum+=a[i][y]-num;
sum+=num;
if(a[i][j]>=sum)ans++;
}
if(ans>=k)return true;
else return false;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
int l=0;
int r=1919810;
while(l+1!=r){
int mid=(l+r)/2;
if(get_ans(mid)){
r=mid;
}
else l=mid;
}
cout<<r<<endl;
return 0;
}
I std::string
#include <iostream>
using namespace std;
int main() {
int taskId;
cin >> taskId;
if (taskId == 1) {
cout << "100000" <<endl;
} else if (taskId == 2) {
cout << "3 0 1 0" << endl;
} else { // 这个 else 不会被执行
cout << "Stupid Fusu!" << endl;
}
}