Codeforces Round #358 (Div. 2)

Alyona and Numbers

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
ll c(ll n,ll p){return (n+p)/5;}
int main()
{
//  freopen("A.in","r",stdin);
//  freopen(".out","w",stdout);
    ll x=read(),y=read();
    ll ans=0;
    Rep(i,5) {
        ans+=c(y,(5-i)%5)*c(x,i);
    }
    cout<<ans<<endl;

    return 0;
}

Alyona and Mex

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
int n;
int a[100000+10];
int main()
{
//  freopen("B.in","r",stdin);
//  freopen(".out","w",stdout);
    cin>>n;
    int p=1;
    For(i,n) {
        a[i]=read();
    }
    sort(a+1,a+1+n);
    For(i,n) {
        if (p<a[i]) a[i]=p,p=p+1;
        else if (p==a[i]) ++p;

    }
    cout<<p<<endl;

    return 0;
}

Alyona and the Tree

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
#define MAXN (100000+10)
int n;
ll a[MAXN];
vi edges[MAXN];
vector<ll> weight[MAXN];
void addedge(int u,int v,int c) {
    edges[u].pb(v);
    edges[v].pb(u);
    weight[u].pb(c);
    weight[v].pb(c);
}
int ans=0;
void dfs(int x,int f,int mxc) {
    if (mxc>a[x]) return;
    int sz=SI(edges[x]);
    Rep(i,sz) {
        int v=edges[x][i],c=weight[x][i];
        if (v==f) continue;
        dfs(v,x,max(mxc+c,0));
    }
    ++ans;
}
int main()
{
//  freopen("C.in","r",stdin);
//  freopen(".out","w",stdout);
    n=read();
    For(i,n) a[i]=read();
    Fork(i,2,n) {
        int v=read(),c=read();
        addedge(i,v,c);
    }
    dfs(1,0,0);
    cout<<n-ans<<endl;
    return 0;
}

Alyona and Strings

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
#define MAXN (1000+10)
#define MAXK (10+10)
int n,m,K;
char s[MAXN],t[MAXN];
int f[MAXN][MAXN][MAXK][2]; 
int main()
{
//  freopen("D.in","r",stdin);
//  freopen(".out","w",stdout);
    cin>>n>>m>>K;
    cin>>s+1>>t+1;
    MEM(f)
    ll ans=0;
    For(i,n)
        For(j,m)
            For(k,K) {
                if (s[i]==t[j]) {
                    f[i][j][k][1]=max(f[i-1][j-1][k][1]+1,max(f[i-1][j-1][k-1][0],f[i-1][j-1][k-1][1])+1);
                }
                else {
                    f[i][j][k][1]=0;
                }
                f[i][j][k][0]=max(max(f[i-1][j][k][0],f[i][j-1][k][0]),max(f[i-1][j][k][1],f[i][j-1][k][1]));
                f[i][j][k][0]=max(f[i][j][k][0],f[i][j][k][1]);
                ans=max(ans,(ll)f[i][j][k][0]);
            }
    cout<<ans<<endl;
    return 0;
}

Alyona and Triangles

找到图中最大的三角形,然后向下图那样对每条边的两侧作2条平行线得到下图
CF682E

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
ll sqr(ll a){return a*a;}
ld sqr(ld a){return a*a;}
double sqr(double a){return a*a;}

class P{
public:
    ll x,y;
    P(ll x=0,ll y=0):x(x),y(y){}
    friend long double dis2(P A,P B){return sqr(A.x-B.x)+sqr(A.y-B.y);  }
    friend long double Dot(P A,P B) {return A.x*B.x+A.y*B.y; }
    friend long double Length(P A) {return sqrt(Dot(A,A)); }
    friend long double Angle(P A,P B) {return acos(Dot(A,B) / Length(A) / Length(B) ); }

    friend P operator- (P A,P B) { return P(A.x-B.x,A.y-B.y); }
    friend P operator+ (P A,P B) { return P(A.x+B.x,A.y+B.y); }
    friend P operator* (P A,double p) { return P(A.x*p,A.y*p); }
    friend P operator/ (P A,double p) { return P(A.x/p,A.y/p); }
    friend bool operator< (const P& a,const P& b) {return a.x<b.x||(a.x==b.x&& a.y<b.y);}

}; 
const double eps=1e-10;
int dcmp(double x) {
    if (fabs(x)<eps) return 0; else return x<0 ? -1 : 1; 
}
bool operator==(const P& a,const P& b) {
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y) == 0;
} 
typedef P V;

ll Cross(V A,V B) {return A.x*B.y - A.y*B.x;}
ll Area2(P A,P B,P C) {return Cross(B-A,C-A);}
int n;
ll S;
P p[5000+10];
int main()
{
//  freopen("E.in","r",stdin);
//  freopen(".out","w",stdout);

    cin>>n>>S;
    Rep(i,n) cin>>p[i].x>>p[i].y;

    int i=0,j=1,k=2;
    ll ans=Area2(p[i],p[j],p[k]);   
    if (ans<0) swap(j,k);
    while(1) {
        bool flag=0;
        Rep(l,n) if (l!=i&&l!=j&&l!=k) {
            if (Area2(p[i],p[j],p[l])>ans) {
                k=l; ans=Area2(p[i],p[j],p[l]); flag=1;
            }
            if (Area2(p[l],p[j],p[k])>ans) {
                i=l; ans=Area2(p[l],p[j],p[k]); flag=1;
            }
            if (Area2(p[i],p[l],p[k])>ans) {
                j=l; ans=Area2(p[i],p[l],p[k]); flag=1;
            }           
        } 
        if (!flag) break;
    }
    P A=p[i]+p[j]-p[k];
    P B=p[j]+p[k]-p[i];
    P C=p[k]+p[i]-p[j];

    printf("%I64d %I64d\n%I64d %I64d\n%I64d %I64d\n",A.x,A.y,B.x,B.y,C.x,C.y);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值