码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #433

时间:2017-09-13 23:19:40      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:ble   技术   sizeof   alt   rtm   stdio.h   efi   algorithm   http   

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

标签:ble   技术   sizeof   alt   rtm   stdio.h   efi   algorithm   http   

原文地址:http://www.cnblogs.com/max88888888/p/7518077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!