求调
查看原帖
求调
550775
rsy_楼主2024/10/29 14:53

不知道是不是被卡格式了,太你吗猥琐了 UVA

#include <bits/stdc++.h>
#define lb(x) (x&-x)
#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)

using namespace std;
using i64 = long long;

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
void chmin(int &x, int c) {
    x = min(x, c);
}
void chmax(int &x, int c) {
    x = max(x, c);
}

// namespace fast_IO{
// #define IOSIZE 100000
// int precision=3,POW[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};char ibuf[IOSIZE],obuf[IOSIZE],*p1=ibuf,*p2=ibuf,*p3=obuf;
// #ifdef ONLINE_JUDGE
// #define getchar()((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))
// #define putchar(x)((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)
// #define isdigit(ch)(ch>47&&ch<58)
// #define isspace(ch)(ch<33)
// #endif
// template<typename T>inline T read(){T s=0;int w=1;char ch;while(ch=getchar(),!isdigit(ch)&&(ch!=EOF))if(ch==45)w=-1;if(ch==EOF)return 0;while(isdigit(ch))s=s*10+ch-48,ch=getchar();return s*w;}template<typename T>inline bool read(T&s){s=0;int w=1;char ch;while(ch=getchar(),!isdigit(ch)&&(ch!=EOF))if(ch==45)w=-1;if(ch==EOF)return 0;while(isdigit(ch))s=s*10+ch-48,ch=getchar();return s*=w,1;}inline bool read(char&s){while(s=getchar(),isspace(s));return 1;}inline bool read(char*s){char ch;while(ch=getchar(),isspace(ch));if(ch==EOF)return 0;while(!isspace(ch))*s++=ch,ch=getchar();*s='\000';return 1;}template<typename T>inline void print(T x){if(x<0)putchar(45),x=-x;if(x>9)print(x/10);putchar(x%10+48);}inline void print(char x){putchar(x);}inline void print(char*x){while(*x)putchar(*x++);}inline void print(const char*x){for(int i=0;x[i];i++)putchar(x[i]);}inline bool read(std::string&s){s="";char ch;while(ch=getchar(),isspace(ch));if(ch==EOF)return 0;while(!isspace(ch))s+=ch,ch=getchar();return 1;}inline void print(std::string x){for(int i=0,n=x.size();i<n;i++)putchar(x[i]);}inline bool read(bool&b){char ch;while(ch=getchar(),isspace(ch));b=ch^48;return 1;}inline void print(bool b){putchar(b+48);}inline bool read(double&x){int a=0,b=0;char ch=getchar();bool f=0;while(ch<48||ch>57){if(ch==45)f=1;ch=getchar();}while(47<ch&&ch<58){a=(a<<1)+(a<<3)+(ch^48);ch=getchar();}if(ch!=46){x=f?-a:a;return 1;}ch=getchar();while(47<ch&&ch<58){b=(b<<1)+(b<<3)+(ch^48),ch=getchar();}x=b;while(x>1)x/=10;x=f?-a-x:a+x;return 1;}inline void print(double x){if(x<0){putchar(45),x=-x;}x=round((long double)x*POW[precision])/POW[precision],print((long long)x),putchar(46),x-=(long long)(x);for(int i=1;i<=precision;i++)x*=10,putchar(x+48),x-=(int)x;}template<typename T,typename...T1>inline int read(T&a,T1&...other){return read(a)+read(other...);}template<typename T,typename...T1>inline void print(T a,T1...other){print(a),print(other...);}struct Fast_IO{~Fast_IO(){fwrite(obuf,p3-obuf,1,stdout);}}io;template<typename T>Fast_IO&operator>>(Fast_IO&io,T&b){return read(b),io;}template<typename T>Fast_IO&operator<<(Fast_IO&io,T b){return print(b),io;}
// #define cout io
// #define cin io
// #define endl '\n'
// }using namespace fast_IO;
const int maxn = 3e5 + 10, mod = 998244353;
int N;
int v[maxn], l[maxn];
struct pt {
    double x, y, w;
    pt operator - (const pt &p) const {
        return {x - p.x, y - p.y, w};
    }
} p[maxn];
double cross (pt i, pt j) {
    return i.x * j.y - i.y * j.x;
}
double dis (pt i, pt j) {
    return sqrt((i.x - j.x) * (i.x - j.x) + (i.y - j.y) * (i.y - j.y));
}
bool cmp (pt i, pt j) {
    if (i.w == j.w) {
        return dis(p[1], i) < dis(p[1], j);
    }
    return i.w < j.w;
}
double x[maxn], y[maxn];
int stk[maxn], top;
int cs;

void solve() {
    cin >> N;
    if (N == 0) exit(0);
    if (cs != 1) cout << '\n';
    L (i, 1, N) {
        cin >> x[i] >> y[i];
        cin >> v[i] >> l[i];
    }
    vector<int> g; g.clear();
    double res2 = 1e9, sc = 0;
    for (int i = 0; i < (1 << N); i ++ ) {
        double c1 = 0, c2 = 0;
        // 1 是砍掉,0 是保留
        int M = 0;
        L (j, 1, N)
            if (i >> (j - 1) & 1) c1 += l[j], c2 += v[j];
            else p[++ M] = {x[j], y[j], atan2(y[j], x[j])};
        // c1:有多少木材
        // c2:得到多少价值
        L (j, 2, M) 
            if (p[j].y < p[1].y || (p[j].y == p[1].y && p[j].x < p[1].x))
                swap (p[j], p[1]);
        if (M) {
            sort (p + 2, p + 1 + M, cmp);
            // M = 0 时越界了!!!
            top = 0;
            stk[++ top] = 1;
            for (int j = 2; j <= M; j ++ ) {
                while (top >= 2 && cross(p[stk[top]] - p[stk[top - 1]], p[j] - p[stk[top]]) <= 0)
                    top -- ;
                stk[++ top] = j;
            }
        }
        double cnt = 0;
        // 周长是多少
        for (int j = 2; j <= top; j ++ ) {
            cnt += dis(p[stk[j - 1]], p[stk[j]]);
        }
        cnt += dis(p[1], p[stk[top]]);
        if (cnt <= c1) {
            // 可以建造
            if (c2 < res2) {
                // 小于当前 res
                // 砍掉哪些
                g.clear();
                for (int j = 1; j <= N; j ++ ) {
                    if (i >> (j - 1) & 1) {
                        g.push_back(j);
                    }
                }
                res2 = c2;
                sc = c1 - cnt;
            } else if (c2 == res2) {
                int cntt = 0;
                for (int j = 1; j <= N; j ++ ) {
                    if (i >> (j - 1) & 1) {
                        cntt ++ ;
                    }
                }
                if (cntt < (int)g.size()) {
                    g.clear();
                    for (int j = 1; j <= N; j ++ ) if (i >> (j - 1) & 1) g.push_back(j);
                    res2 = c2, sc = c1 - cnt;
                }
            }
        }
    }
    cout << "Forest " << cs << '\n';
    cout << "Cut these trees: ";
    for (int i = 0; i < (int)g.size(); i ++ ) {
        if (i == (int)g.size() - 1) {
            cout << g[i];
        } else {
            cout << g[i] << ' ';
        }
    }
    cout << "\n";
    cout << "Extra wood: " << fixed << setprecision(2) << sc << '\n';
    cs ++ ;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cs = 1;
    while (cs)solve();
    return 0;
}
2024/10/29 14:53
加载中...