一天打两场,爽到(确信
传送门:https://atcoder.jp/contests/abc161/
A
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c; cin>>a>>b>>c;
swap(a, c), swap(b, c);
cout<<a<<' '<<b<<' '<<c<<endl;
return 0;
}
B
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int w[N];
int main(){
int n, m; cin>>n>>m;
int s=0;
for(int i=1; i<=n; i++) cin>>w[i], s+=w[i];
sort(w+1, w+1+n, greater<int>());
int lim=(s+4*m-1)/(4*m);
for(int i=1; i<=m; i++) if(w[i]<lim){
puts("No");
return 0;
}
puts("Yes");
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n, k; cin>>n>>k;
n%=k;
cout<<min(n, k-n)<<endl;
return 0;
}
D
根据样例可以发现极限也不是很大,我们考虑枚举。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
#define int long long
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
set<int> buf;
void dfs(int last, int cur, int bit){
if(bit>1e10) return;
if(last==-1){
rep(i,0,9){
int v=i*bit;
buf.insert(v);
dfs(i, v, bit*10);
}
}
else{
rep(i,last-1,last+1){
if(i<0 || i>9) continue;
int v=i*bit+cur;
buf.insert(v);
dfs(i, v, bit*10);
}
}
}
signed main(){
int k; read(k);
dfs(-1, 0, 1);
buf.erase(*buf.begin());
int cnt=0;
for(auto i: buf){
cnt++;
if(cnt==k){
cout<<i;
return 0;
}
}
return 0;
}
E
大力贪心,正着扫一遍,看看最早需要工作的点 \(l[i]\),然后倒着扫一遍,看看最晚需要工作的点 \(r[i]\),如果 \(l[i]=r[i]\) ,那么第 \(l[i]\) 天就必选,否则就必不选。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=2e5+5;
int l[N], r[N], tl, tr;
int main(){
int n, k, c; read(n), read(k), read(c);
string s; cin>>s; s=' '+s;
int cnt=INF;
rep(i,1,n){
if(s[i]=='x'){
cnt++;
continue;
}
if(cnt>=c){
l[++tl]=i;
// debug(i);
if(tl>=k) continue;
cnt=0;
continue;
}
cnt++;
}
cnt=INF;
dwn(i,n,1){
if(s[i]=='x'){
cnt++;
continue;
}
if(cnt>=c){
r[++tr]=i;
if(tr>=k) continue;
cnt=0;
continue;
}
cnt++;
}
// debug(tl);
rep(i,1,k) if(l[i]==r[k+1-i]) cout<<l[i]<<endl;
return 0;
}
F
打表找规律
发现可能的结果只包括 \(n,n-1\) 的因数,check 一下是否合法加入答案就可以了。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
#define int long long
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
bool ok(int n, int k){
while(n>=k){
if(n%k==0) n/=k;
else n%=k;
}
return n==1;
}
set<int> buf;
vector<int> divisor(int x){
vector<int> res;
for(int i=2; i<=x/i; i++){
if(x%i==0){
res.push_back(i);
if(x/i!=i) res.push_back(x/i);
}
}
return res;
}
signed main(){
ll n; cin>>n;
auto t=divisor(n);
if(n==2){
puts("1");
return 0;
}
for(auto i: t){
// debug(i);
int v=i;
if(v==1) continue;
if(ok(n, v)) buf.insert(v);
}
t=divisor(n-1);
for(auto i: t){
// debug(i);
int v=i;
if(v==1) continue;
if(ok(n, v)) buf.insert(v);
}
buf.insert(n), buf.insert(n-1);
cout<<buf.size();
return 0;
}