2019 Multi-University Training Contest 10

1003 - Valentine's Day

#include "bits/stdc++.h"

using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-8;
double dcmp(double a) {
    if (a > eps)return 1;
    if (a < -eps)return -1;
    return 0;
}
struct node {
    double p1, p0;
    bool friend operator < (node a,node b){
        return dcmp(a.p1-b.p1)>0;
    }
};



double p[10004];

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        scanf("%d", &n);
        double ans = 0;
        vector<node> v;
        bool ok = 0;
        for (int i = 0; i < n; ++i) {
            scanf("%lf", &p[i]);
            if (dcmp(p[i] - 0.5) >= 0) {
                ans = max(ans, p[i]);
                ok = 1;
            } else v.push_back({p[i], 1.0 - p[i]});
        }
        if(ok){
            printf("%.12f\n",ans);
            continue;
        }
        node now;
        sort(v.begin(),v.end());
        if(v.size()){
            now = v[0];
            for (int i = 1; i < v.size() ; ++i) {
                ans = max(ans, now.p1);
                node t = now;
                now.p0 = (t.p0*v[i].p0);
                now.p1 = (t.p0 * v[i].p1 + t.p1 * v[i].p0);
            }
        }
        printf("%.12f\n",max(now.p1,ans));
    }
}

 1005 - Welcome Party 

#include "bits/stdc++.h"

using namespace std;
const int mod = 1e9 + 7;
struct node {
    long long a;long long b;
    bool friend operator < (node a,node b){
        return a.a>b.a;
    }
}p[100004];
int main() {
    int t;
    cin>>t;
    while (t--){
        int n;
        cin>>n;
        multiset<long long>ms;
        for (int i = 0; i < n; ++i) {
            scanf("%lld%lld",&p[i].a,&p[i].b);
            ms.insert(p[i].b);
        }
        sort(p,p+n);
        long long maxi = -1;
        long long ans = 1e18;
        for (int i = 0; i < n; ++i) {
            ms.erase(ms.find(p[i].b));//迭代器
            multiset<long long>::iterator it1 = ms.lower_bound(p[i].a);//迭代器
            multiset<long long>::iterator it2 = ms.lower_bound(p[i].a);//迭代器
            if(it1!=ms.begin()){
                it1--;
                if(*it1 >= maxi){
                    ans = min(ans, abs(p[i].a - *it1));
                }
            }
            if(it2!=ms.end()){
                if(*it2 >= maxi){
                    ans = min(ans, abs(p[i].a - *it2));
                }
            }
            if(maxi != -1)ans = min(ans, abs(maxi - p[i].a));
            maxi = max(maxi, p[i].b);
        }
        //cout<<ans<<endl;
        printf("%lld\n",ans);
    }
}

1009 - Block Breaker 

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 2007;
const int dir[4][2] =
        {
                -1, 0,
                0, -1,
                1, 0,
                0, 1
        };
int N, M, Q;
bool vis[maxN][maxN];
inline bool In_Map(int x, int y) { return x > 0 && y > 0 && x <= N && y <= M; }
inline bool check(int x, int y)
{
    bool flag_UD = false, flag_LR = false;
    if(In_Map(x-1, y) && vis[x-1][y]) flag_UD = true;
    if(In_Map(x+1, y) && vis[x+1][y]) flag_UD = true;
    if(In_Map(x, y-1) && vis[x][y-1]) flag_LR = true;
    if(In_Map(x, y+1) && vis[x][y+1]) flag_LR = true;
    return flag_UD && flag_LR;
}
struct node
{
    int x, y;
    node(int a=0, int b=0):x(a), y(b) {}
};
int bfs(int sx, int sy)
{
    int ans = 0;
    if(vis[sx][sy]) return 0;
    vis[sx][sy] = true;
    queue<node> Q;
    Q.push(node(sx, sy));
    while(!Q.empty())
    {
        node now = Q.front(); Q.pop();
        for(int i=0, xx, yy; i<4; i++)
        {
            xx = now.x + dir[i][0]; yy = now.y + dir[i][1];
            if(!In_Map(xx, yy) || vis[xx][yy] || !check(xx, yy)) continue;
            vis[xx][yy] = true; ans++;
            Q.push(node(xx, yy));
        }
    }
    return ans+1;
}
inline void init()
{
    for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) vis[i][j] = false;
}
int main()
{
    int Cas; scanf("%d", &Cas);
    while(Cas--)
    {
        scanf("%d%d%d", &N, &M, &Q);
        init();
        int xi, yi;
        while (Q--)
        {
            scanf("%d%d", &xi, &yi);
            printf("%d\n", bfs(xi, yi));
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值