Codeforces Round #433

Posted %%%%%

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #433相关的知识,希望对你有一定的参考价值。

A.Fraction

思路:暴力

AC代码:

技术分享
#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define step(x) fixed<< setprecision(x)<<
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ll long long
#define endl ("\n")
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const ll mod=1e9+7;
const ll INF = 1e18+1LL;
const int inf = 1e9+1e8;
const double PI=acos(-1.0);
const int N=1e5+100;

int n,a,b;
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1; i<=n/2; ++i){
        int g=__gcd(i,n-i);
        if(g==1){
            a=max(a,i);
        }
    }
    cout<<a<<" "<<n-a<<endl;
    return 0;
}
View Code

 

B.Maxim Buys an Apartment

AC代码:

技术分享
#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define step(x) fixed<< setprecision(x)<<
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ll long long
#define endl ("\n")
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const ll mod=1e9+7;
const ll INF = 1e18+1LL;
const int inf = 1e9+1e8;
const double PI=acos(-1.0);
const int N=1e5+100;

ll n,k,mi,ma;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cin.tie(0);
    cin>>n>>k;
    if(n!=k && k!=0) mi=1;
    int a=n/3, b=k-a;
    int ans=2*a;
    if(k<=a){
        ans=k*2;
        cout<<mi<<" "<<ans<<endl;
    }
    else{
        int l=n-3*a;
        if(l==1){
            b--;
        }
        if(l==2){
            b-=2;
        }
        cout<<mi<<" "<<ans-b<<endl;
    }
    return 0;
}
View Code

 

C.Planning

思路:贪心

AC代码:

技术分享
#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define step(x) fixed<< setprecision(x)<<
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ll long long
#define endl ("\n")
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const ll mod=1e9+7;
const ll INF = 1e18+1LL;
const int inf = 1e9+1e8;
const double PI=acos(-1.0);
const int N=1e5+100;

struct Node{
    ll t,c;
    bool friend operator< (Node a, Node b){
        return a.c<b.c;
    }
};
Node a[N],now;
priority_queue<Node> Q;
ll c[N],n,k;
ll ans;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for(int i=1; i<=n; ++i){
        cin>>a[i].c; a[i].t=i;
    }
    for(int i=1; i<=k; ++i){
        Q.push(a[i]);
    }
    int l=0;
    for(int i=k+1; i<=n+k; ++i){
        if(i<=n){
            Q.push(a[i]);
        }
        now=Q.top();
        Q.pop();
        ans += (i-now.t)*now.c;
        c[now.t]=i;
    }
    cout<<ans<<endl;
    for(int i=1; i<=n; ++i){
        cout<<c[i]<<" ";
    }
    return 0;
}
View Code

 

以上是关于Codeforces Round #433的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #433

codeforces round #433 div2

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

codeforces比赛题解#854 CF Round #433 (Div.2)

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning