AtCoder Beginner Contest 131 Solution

6935 단어
전언
이번엔 ABC가 좀 어려울 것 같은데.
TaskA Security
Solution
직접 시뮬레이션을 하면 돼요.
Code
/*
  mail: [email protected]
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
char s[100010];
int main(){
    scanf("%s",s+1);
    for(int i=1;i

TaskB Bite Eating
Solution
그걸 일일이 열거해서 삭제하고 판단하면 돼.
Code
/*
  mail: [email protected]
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
int n,L,a[210];
int main(){
    n=gi();L=gi();int Sum=0;
    for(int i=1;i<=n;i++)a[i]=L+i-1,Sum+=a[i];
    int Min=1e9+10,ans;
    for(int i=1;i<=n;i++){
        int sum=0;
        for(int j=1;j<=n;j++)if(i!=j)sum+=a[j];
        
        if(abs(Sum-sum)

TaskC Anti-Division
Solution
\(gcd\) 허용을 구하면 됩니다.
Code
/*
  mail: [email protected]
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define int ll
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
ll get(ll a,ll b,ll c){
    return (b-a+1)-(b/c-(a-1)/c);
}
ll gcd(ll a,ll b){
    if(!b)return a;
    return gcd(b,a%b);
}
ll a,b,sumc,sumd,sumcd;int c,d;
signed main(){
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    printf("%lld
",get(a,b,c)+get(a,b,d)-get(a,b,1ll*c*d/gcd(c,d))); return 0; }

TaskD Megalomania
Solution
가장 늦게 완성된 시간에 따라 순서를 정하고 시뮬레이션을 하면 됩니다.
Code
/*
  mail: [email protected]
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define int ll
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
struct node{int x,y;}job[200010];
int n;
bool operatorjob[i].y)return puts("No"),0;
    }
    puts("Yes");
    return 0;
}

TaskE Friendships
Solution
국화도를 가장 많이 고려하면 한 걸음 한 걸음 국화도에 가장자리를 넣으면 된다.
Code
/*
  mail: [email protected]
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
int n,k;
struct node{int x,y;}edge[1000010];
int main(){
    n=gi();k=gi();
    int tot=(n-2)*(n-1)/2,m=n-1;
    for(int i=1;i<=m;i++)edge[i].x=n,edge[i].y=i;
    if(k>tot)return puts("-1"),0;int now=2,Q=1;
    n--;
    while(tot!=k){
        tot--;
        edge[++m]=(node){now,(now+Q-1)%n+1};
        now++;now=(now-1)%n+1;
        if(now==2)Q++;
    }
    printf("%d
",m); for(int i=1;i<=m;i++) printf("%d %d
",edge[i].x,edge[i].y); return 0; }

TaskF Must Be Rectangular!
Solution
\(yyb\)바로 신선이다!!!하나의 점의\(x, y\)를 분할하는 것을 고려하면\(x\)->\(y\) 연결에 해당한다. 그리고 연결 블록을 고려하면 완전한 그림을 만들 수 있다. 그러면 완전한 그림의 변수는 점수이다.마지막에 최초의 점수를 바로 빼면 없어진다.
Code
/*
  mail: [email protected]
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define MAX 100100
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
int n,f[MAX<<1];
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
int sz1[MAX<<1],sz2[MAX<<1];
ll ans;
int main(){
    n=gi();
    for(int i=1;i

전재 대상:https://www.cnblogs.com/mleautomaton/p/11071739.html

좋은 웹페이지 즐겨찾기