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

Codeforces Round #367 (Div. 2) 题解

时间:2016-08-13 06:31:23      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

A

code:

技术分享
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define maxn 1005
using namespace std;
int main()
{
    double ans,tans;
    double x0,y0,x,y,v;
    cin >> x0 >> y0;
    ans = 100000000;
    //cout << ans << endl;
    int n;
    cin >> n;
    for(int i = 0;i < n;i ++){
        cin >> x >> y >> v;
        double dx,dy;
        dx = x - x0;dy = y - y0;
        tans = sqrt(dx*dx+dy*dy);
        tans /= v;
        if(tans < ans) ans = tans;
    }
    printf("%.8lf\n",ans);
    return 0;
}
View Code

BA

code:

技术分享
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 100005
using namespace std;
int price[maxn];
int main()
{
    int n,q;
    scanf("%d",&n);
    for(int i = 0;i < n;i ++) scanf("%d",&price[i]);
    sort(price,price+n);
    scanf("%d",&q);
    for(int i = 0;i < q;i ++){
        int s,e,m,pp;
        scanf("%d",&pp);
        s = 0,e = n - 1;
        while(s <= e){
            m = (s+e) >> 1;
            if(price[m] <= pp) s = m + 1;
            else e = m - 1;
        }
        cout << s << endl;
    }
    return 0;
}
View Code

C

code:

技术分享
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define maxn 100005
#define mmax 1e18
using namespace std;
typedef long long ll;
ll dp[maxn][2];
ll c[maxn];
string f(string s){
    string ss;
    for(int i = s.size() - 1;i >= 0;i --){
        ss += s[i];
    }
    return ss;
}
int main()
{
    int n;
    bool done = false;
    string s[maxn];
    cin >> n;
    for(int i = 1;i <= n;i ++) scanf("%d",&c[i]);
    for(int i = 1;i <= n;i ++) cin >> s[i];
    s[0] = "a";
    memset(dp,0,sizeof(dp));
    for(int i = 1;i <= n;i ++ ){
        ll t1,t2,t3,t4;
        dp[i][0] = dp[i][1] = -1;
        t1 = t2 = t3 = t4 = mmax;
        bool flag = false;
        if(dp[i-1][0] >= 0 && s[i].compare(s[i-1]) >= 0) {t1 = dp[i-1][0];flag = true;}
        if(dp[i-1][1] >= 0 && s[i].compare(f(s[i-1])) >= 0) {t2 = dp[i-1][1];flag = true;}
        if(dp[i-1][0] >= 0 && f(s[i]).compare(s[i-1]) >= 0) {t3 = dp[i-1][0] + c[i];flag = true;}
        if(dp[i-1][1] >= 0 && f(s[i]).compare(f(s[i-1])) >= 0) {t4 = dp[i-1][1] + c[i];flag = true;}
        if(!flag) {cout << "-1" << endl;done = true;break;}
        if(t1 != mmax || t2 != mmax) dp[i][0] = min(t1,t2);
        if(t3 != mmax || t4 != mmax) dp[i][1] = min(t3,t4);
    }
    if(!done){
        if(dp[n][0] == -1) cout << dp[n][1] << endl;
        else if(dp[n][1] == -1) cout << dp[n][0] << endl;
        else cout << min(dp[n][0],dp[n][1]) << endl;
    }
    return 0;
}
View Code

D

code:

技术分享
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 200005
using namespace std;
typedef long long ll;
int c[32];
int a[32];
struct node{
    int cnt;
    node* next[2];
};
int ans;
void init(){
    c[0] = 1;
    for(int i = 1;i < 32;i ++) c[i] = c[i-1]*2;
}
void bulitTree(node* root,int x,bool isAdd){
    if(x == 31) return;
    node *tmp = (node*)malloc(1*sizeof(node));
    tmp->next[0] = tmp->next[1] = NULL;
    tmp->cnt = 0;
    if(a[x] == 0){
        if(!root->next[0]) root->next[0] = tmp;
        root->next[0]->cnt += (isAdd == true?1:-1);
        bulitTree(root->next[0],x+1,isAdd);
    }
    if(a[x] == 1){
        if(!root->next[1]) root->next[1] = tmp;
        root->next[1]->cnt += (isAdd == true?1:-1);
        bulitTree(root->next[1],x+1,isAdd);
    }
}
bool searchTree(node* root,int x){
    if(root == NULL || root->cnt == 0) {return false;}
    if(x == 31 && root->cnt > 0) return true;
    if(a[x] == 0){
        ans += c[30-x];
        if(searchTree(root->next[1],x+1)) return true;
        ans -= c[30-x];
        searchTree(root->next[0],x+1);
    }
    else{
        ans += c[30-x];
        if(searchTree(root->next[0],x+1)) return true;
        ans -= c[30-x];
        searchTree(root->next[1],x+1);
    }
    return true;
}
int main()
{
    int q,x;
    node root;
    root.next[0] = root.next[1] = NULL;
    root.cnt = 1;
    char op;
    cin >> q;
    memset(a,0,sizeof(a));
    init();
    bulitTree(&root,0,true);
    for(int i = 1;i <= q;i ++){
        cin >> op >> x;
        for(int i = 30;i >= 0;i --){
            if(x == 0) a[i] = 0;
            else a[i] = x%2;
            x /= 2;
        }
        if(op == +) {
            bulitTree(&root,0,true);
        }
        else if(op == -){
            bulitTree(&root,0,false);
        }
        else{
            ans = 0;
            searchTree(&root,0);
            cout << ans << endl;
        }
    }
    return 0;
}
View Code

 

Codeforces Round #367 (Div. 2) 题解

标签:

原文地址:http://www.cnblogs.com/zhangjialu2015/p/5767084.html

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