temp

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
#define inf 0x7f7f7f7f
#define N 30005
#define lb(x) (x&(-x))
using namespace std;
ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c<='9' && c>='0') {x=x*10+c-'0';c=getchar();}
    return x*f;
}
struct nod
{
    int op,x,y,k,id,cur;
}q[N],tmp[N];
int n,m,x,y,z,tot,a[N],Count,ans[N],t[N],tmpp[N];
char c[5];
bool mark[N];
void add(int x,int v)
{
    while(x<=n)
    {
        t[x]+=v;
        x+=lb(x);
    }
}
int query(int x)
{
    int ret=0;
    while(x)
    {
        ret+=t[x];
        x-=lb(x);
    }
    return ret;
}
void solve(int l,int r,int L,int R)
{
    if(l>r) return ;
    if(L==R)
    {
        for(int i=l;i<=r;i++) if(q[i].op==3) ans[q[i].id]=L;
        return ;
    }
    int mid=(L+R)>>1;
    for(int i=l;i<=r;i++)
    {
        if(q[i].op==1 && q[i].y<=mid) add(q[i].x,1);
        else if(q[i].op==2 && q[i].y<=mid) add(q[i].x,-1);
        else if(q[i].op==3) tmpp[i]=query(q[i].y)-query(q[i].x-1);
    }
    for(int i=l;i<=r;i++)
    {
        if(q[i].op==1 && q[i].y<=mid) add(q[i].x,-1);
        else if(q[i].op==2 && q[i].y<=mid) add(q[i].x,1);
    }
    int cnt=0;
    for(int i=l;i<=r;i++)
    {
        if(q[i].op==3)
        {
            if(q[i].cur+tmpp[i]>=q[i].k) cnt++,mark[i]=1;
            else q[i].cur+=tmpp[i],mark[i]=0;
        }
        else
        {
            if(q[i].y<=mid) cnt++,mark[i]=1;
            else mark[i]=0;
        }
    }
    int l1=l,l2=l+cnt;
    for(int i=l;i<=r;i++)
    {
        if(mark[i]) tmp[l1++]=q[i];
        else tmp[l2++]=q[i];
    }
    for(int i=l;i<=r;i++) q[i]=tmp[i];
    solve(l,l1-1,L,mid);solve(l1,l2-1,mid+1,R);
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)
    {
        a[i]=read();
        q[++tot].op=1;q[tot].x=i;q[tot].y=a[i];q[tot].id=0;
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%s",c);
        x=read(),y=read();
        if(c[0]=='C')
        {
            q[++tot].op=2;q[tot].x=x;q[tot].y=a[x];q[tot].id=0;
            q[++tot].op=1;q[tot].x=x;q[tot].y=y;q[tot].id=0;
            a[x]=y;
        }
        else
        {
            z=read();
            q[++tot].op=3;q[tot].x=x;q[tot].y=y;q[tot].k=z;q[tot].id=++Count;
        }
    }
    solve(1,tot,0,inf);
    for(int i=1;i<=Count;i++) printf("%d\n",ans[i]);
    return 0;
} 

 

#include "cstdio"
#define lowbit(x) (x & (-x)) 
 
using namespace std;
 
const int Nmax = 50005;
 
int N, M;
struct Option{
    int sign, x, y, c;
}op[Nmax];
 
int tot = -1, ans[Nmax];
int q[Nmax], tmp[2][Nmax];
 
namespace BIT{
    int t[Nmax][2], d[Nmax][2];
 
    void update(bool s, int pos, int c)
    {
        for (int i = pos; i <= N; i += lowbit(i)) {
            if (t[i][s] != tot) { t[i][s] = tot; d[i][s] = 0; }
            d[i][s] += c;
        }
    }
     
    int get_sum(bool s, int pos)
    {
        int res = 0;
        for (int i = pos; i; i -= lowbit(i)) {
            if (t[i][s] != tot) { t[i][s] = tot; d[i][s] = 0; }
            res += d[i][s];
        }
        return res;
    }
     
    void Add(int x, int y)
    {
        update(0, x, 1); update(0, y + 1, -1);
        update(1, x, x); update(1, y + 1, -(y + 1));
    }
     
    int Query(int x, int y)
    {
        int temp = get_sum(0, y) * (y + 1) - get_sum(1, y);
        temp -= get_sum(0, x - 1) * x - get_sum(1, x - 1);
        return temp;
    }
}
 
void solve(int L, int R, int l, int r)
{
    if (L > R) return;
     
    ++tot; int mid = (l + r) >> 1;
    if (l == r) {
        for (int i = L; i <= R; ++i) if (op[q[i]].sign == 2) ans[q[i]] = mid;
        return;
    }
     
    tmp[0][0] = tmp[1][0] = 0; using namespace BIT;
    for (int i = L; i <= R; ++i) {
        int temp = q[i];
        if (op[temp].sign == 1) {
            if (op[temp].c <= mid) tmp[0][++tmp[0][0]] = temp;
            else {
                tmp[1][++tmp[1][0]] = temp;
                Add(op[temp].x, op[temp].y);
            }
        } else {
            int cnt = Query(op[temp].x, op[temp].y);
            if (cnt < op[temp].c) {
                op[temp].c -= cnt;
                tmp[0][++tmp[0][0]] = temp;
            } else tmp[1][++tmp[1][0]] = temp;
        }
    }
     
    int tl = L, t2 = L + tmp[0][0] - 1;
    for (int i = 1; i <= tmp[0][0]; ++i) q[tl++] = tmp[0][i];
    for (int i = 1; i <= tmp[1][0]; ++i) q[tl++] = tmp[1][i];
    solve(L, t2, l, mid); solve(t2 + 1, R, mid + 1, r);
}
 
int main()
{
    scanf("%d%d", &N, &M);
    for (int i = 1; i <= M; ++i) {
        scanf("%d%d%d%d", &op[i].sign, &op[i].x, &op[i].y, &op[i].c);
        q[i] = i;
    }
    solve(1, M, 1, N);
    for (int i = 1; i <= M; ++i) {
        if (op[i].sign == 2) printf("%d\n", ans[i]);
    }
     
    return 0;
}

 

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 25
const double eps=0.00000001,inf=1e15;

int n,m,id[maxn*2];
double a[maxn][maxn];//a[i][j]:i表第几条约束 j表第几个元素
double myabs(double x) {return x>0?x:-x;}
//a[0][i] -> ci 目标函数中第i个元素系数
//a[i][0] -> bi 第i条约束中的常数
//a[i][j] -> Aij 第i条约束中第j个元素的系数
//最大化 sigma(ci*xi),i∈N
//约束 xj=bj-sigma(aji*xi) ,j∈B

//转轴
void pivot(int l,int e)
//替入变量xe∈非基本变量(1~n)  替出变量xl∈基本变量(n+1~n+m)
{
    int tt=id[n+l];id[n+l]=id[e];id[e]=tt;
    int i,j;double t=a[l][e];a[l][e]=1;
    for (j=0;j<=n;j++) a[l][j]/=t;
    //重写其它等式:
    for (i=0;i<=m;i++)
     if (i!=l && myabs(a[i][e])>eps)
     {
        t=a[i][e];a[i][e]=0;
        for (j=0;j<=n;j++)
          a[i][j]-=a[l][j]*t;
     }
}

//初始化
//方法一:引入一个辅助线性规划 要求最大化-x0
//约束为 xj=bj-sigma(aji*xi)+x0 ,j∈B然后用x0替换bj为负的约束
//下面的是方法二:
bool initialize()
{
    while (1)
    {
        int i,j,e=0,l=0;
        for (i=1;i<=m;i++) 
            if (a[i][0]<-eps && (!l || (rand()&1))) l=i;
        if (!l) break;
        for (j=1;j<=n;j++) 
          if (a[l][j]<-eps && (!e || (rand()&1))) e=j;
        if (!e) {printf("Infeasible\n");return 0;}
        pivot(l,e);
        //在bi为负的时候,把所有基变量设为0不是一组合法的初始解
        //所以选择一个bi为负的基变量x[i+n]
        //然后在该约束右边找一个系数为正(即原系数为负)的非基变量进行转轴操作
        //如果没有系数为正显然就无解了
    }return 1;
}

//最优化
bool simplex()
{
    int i,j;
    while (1)
    {
        int l=0,e=0;double minn=inf;
        for (j=1;j<=n;j++)
         if (a[0][j]>eps) {e=j;break;}
        if (!e) break;
        //如果目标变量ci都小于0 那么最优解就是非基变量都为0
        for (i=1;i<=m;i++)
         if (a[i][e]>eps && a[i][0]/a[i][e]<minn)
          minn=a[i][0]/a[i][e],l=i;
        //在所有的式子中找出包含当前选中项(系数不为0)且最紧的一项
        if (!l) {printf("Unbounded\n");return 0;}
        //如果所有的a[i][e]都小于0,说明最优值正无穷
        pivot(l,e);
    }return 1;
}
double ans[maxn];

int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    srand(time(0));int t,i,j;
    scanf("%d%d%d",&n,&m,&t);
    //n个变量 m条约束
    for (i=1;i<=n;i++) scanf("%lf",&a[0][i]);
    for (i=1;i<=m;i++)
    {
        for (j=1;j<=n;j++)
          scanf("%lf",&a[i][j]);
        scanf("%lf",&a[i][0]);
    }
    for (i=1;i<=n;i++) id[i]=i;
    if (initialize() && simplex())
    {
        printf("%.8lf\n",-a[0][0]);
        if (t)
        {
            for (i=1;i<=m;i++) ans[id[n+i]]=a[i][0];
            for (i=1;i<=n;i++) printf("%.8lf ",ans[i]);
        }
    }
    return 0;
}

 

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author xyiyy @https://github.com/xyiyy
 */

#include <iostream>
#include <fstream>

//#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>

using namespace std;
#define mp(X, Y) make_pair(X,Y)
#define rep(X, N) for(int X=0;X<N;X++)

//
// Created by xyiyy on 2015/8/10.
//

#ifndef JHELPER_EXAMPLE_PROJECT_P_HPP
#define JHELPER_EXAMPLE_PROJECT_P_HPP

const double EPS = 1e-9;

double add(double a, double b) {
    if (fabs(a + b) < EPS * (fabs(a) + fabs(b)))return 0;
    return a + b;
}

class P {
public:
    double x, y;

    P() { }

    P(double x, double y) : x(x), y(y) { }

    P  operator+(const P &p) {
        return P(add(x, p.x), add(y, p.y));
    }

    P operator-(const P &p) {
        return P(add(x, -p.x), add(y, -p.y));
    }

    P operator*(const double &d) {
        return P(x * d, y * d);
    }

    P operator/(const double &d) {
        return P(x / d, y / d);
    }

    double dot(P p) {
        return add(x * p.x, y * p.y);
    }


    double abs() {
        return sqrt(abs2());
    }

    double abs2() {
        return dot(*this);
    }

};



//直线和直线的交点
/*P isLL(P p1,P p2,P q1,P q2){
    double d = (q2 - q1).det(p2 - p1);
    if(sig(d)==0)return NULL;
    return intersection(p1,p2,q1,q2);
}*/


//四点共圆判定
/*bool onC(P p1,P p2,P p3,P p4){
    P c = CCenter(p1,p2,p3);
    if(c == NULL) return false;
    return add((c - p1).abs2(), -(c - p4).abs2()) == 0;
}*/

//三点共圆的圆心


#endif //JHELPER_EXAMPLE_PROJECT_P_HPP

const int MAXN = 710;
P ps[MAXN];
pair<double, bool> arc[MAXN];

class poj1981 {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        P t;
        while (in >> n && n) {
            rep(i, n)in >> ps[i].x >> ps[i].y;
            int ans = 1;
            rep(i, n) {
                int num = 0;
                rep(j, n) {
                    if (i == j)continue;
                    double d;
                    if ((d = (ps[i] - ps[j]).abs()) <= 2) {
                        double a = acos(d / 2);
                        double b = atan2((ps[j].y - ps[i].y), (ps[j].x - ps[i].x));
                        arc[num++] = mp(b - a, 1);
                        arc[num++] = mp(b + a, 0);
                    }
                }
                sort(arc, arc + num);
                int res = 1;
                rep(j, num) {
                    if (arc[j].second)res++;
                    else res--;
                    ans = max(ans, res);
                }
            }
            out << ans << endl;
        }
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    poj1981 solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

  

posted @ 2018-09-26 01:11  AutSky_JadeK  阅读(245)  评论(0)    收藏  举报
TVアニメ「Charlotte(シャーロット)」公式サイト TVアニメ「Charlotte(シャーロット)」公式サイト