aa

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e4+5,M=2e4+5;
typedef long long ll;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int n,m,u,v;
struct edge{
    int v,ne;
}e[M];
int h[N],cnt=0;
inline void ins(int u,int v){
    cnt++;
    e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
}
int f[N];
int dp(int u){
    if(f[u]) return f[u];
    f[u]=100;
    for(int i=h[u];i;i=e[i].ne){
        int v=e[i].v;
        f[u]=max(f[u],dp(v)+1);
    }
    return f[u];
}
int vis[N],flag=0;
void dfs(int u){
    if(flag) return;
    vis[u]=1;
    for(int i=h[u];i;i=e[i].ne){
        int v=e[i].v;
        if(vis[v]){flag=1;return;}
        dfs(v);
    }
    vis[u]=0;
}
int main(){
    freopen("Reward.in","r",stdin);
    freopen("Reward.out","w",stdout);
    n=read();m=read();
    for(int i=1;i<=m;i++){u=read();v=read();ins(u,v);}
    
    for(int i=1;i<=n;i++){
        //memset(vis,0,sizeof(vis));
        dfs(i);
        if(flag){puts("Poor Xed");return 0;}
    }
    
    ll ans=0;
    for(int i=1;i<=n;i++) ans+=dp(i);
    printf("%lld",ans);    
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=1e5+5;
const ll MOD=4294967296;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
char s[100];
int a[15],t[15],mp[300];
int f[15][40];
void tobit(){
    for(int i=1;i<=9;i++){
        int t=a[i];
        for(int j=0;t;t>>=1,j++)
            if(t&1) f[i][j]=1; 
    }
}
int fm[40];
void sol(){
    int g=0;
    for(int j=0;j<=32;j++){
        int t1=0,t2=0;
        for(int i=1;i<=8;i++) t1+=f[i][j],t2+=(f[i][j]^1);
        t1+=g;t2+=g;
        if((t1&1)==f[9][j]) fm[j]=0,g=t1/2;
        else fm[j]=1,g=t2/2;
    }
}
char st[10];int top=0;
void print(){
    ll m=0;
    for(int j=0;j<=32;j++) m+=(1<<j)*fm[j];
    //printf("m %d\n",m);
    if(m==0) printf("0");
    else while(m){
        int t=m%16; m/=16;
        if(t<10) st[++top]=t+'0';
        else st[++top]=t-10+'a';        
    }
    while(top) putchar(st[top--]);
}
int main(){
    freopen("Encode.in","r",stdin);
    freopen("Encode.out","w",stdout);
    for(int i=0;i<=9;i++) mp[i+'0']=i;
    mp['a']=10;mp['b']=11;mp['c']=12;mp['d']=13;mp['e']=14;mp['f']=15;
    for(int i=1;i<=9;i++){
        scanf("%s",s);
        int len=strlen(s);
        for(int j=0;j<len;j++){
            int p=len-1-j;
            //printf("%c %d %d\n",s[j],mp[s[j]],p);
            a[i]+=mp[s[j]]*pow(16,p);
        }
    }
    tobit();
    sol();
    //for(int i=0;i<=32;i++) printf("%d",fm[i]);
    print();
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1505,M=1e6,INF=1e9;
typedef long long ll;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int n,m,gn;
struct edge{
    int v,w,ne;
}e[M];
int h[N],cnt=0;
inline void ins(int u,int v,int w){//printf("ins %d %d %d\n",u,v,w);
    cnt++;
    e[cnt].v=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=cnt;
}
struct task{
    int t,a,b;
}a[N];

void buildGraph(){
    for(int i=0;i<=gn;i++){
        int has=0;
        for(int j=1;j<=n;j++)
            if(a[j].a<=i&&i<=a[j].b) has++,ins(i,i+a[j].t,a[j].t);        
        if(!has&&i<gn) ins(i,i+1,0);
    }
}

int q[N],head=1,tail=1;
inline void lop(int &x){if(x==N) x=1;}
int d[N],inq[N];
void spfa(){
    for(int i=0;i<=gn;i++) d[i]=INF;
    d[0]=0;
    q[tail++]=0; inq[0]=1;
    while(head!=tail){
        int u=q[head++];inq[u]=0;lop(head);
        for(int i=h[u];i;i=e[i].ne){
            int v=e[i].v,w=e[i].w;
            if(d[v]>d[u]+w){
                d[v]=d[u]+w;
                if(!inq[v]){q[tail++]=v;inq[v]=1;lop(tail);}
            }
        }
    }
}
int main(){
    freopen("Work.in","r",stdin);
    freopen("Work.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++){
        a[i].t=read();a[i].a=read();a[i].b=read()-a[i].t;
        gn=max(gn,a[i].b+a[i].t);
    }
    buildGraph();
    spfa();
    //for(int i=0;i<=gn;i++) printf("d %d %d\n",i,d[i]);
    printf("%d",d[gn]);
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+5;
typedef unsigned long long ll;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
ll n,m,x=0,y=1;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){
    freopen("Sum.in","r",stdin);
    freopen("Sum.out","w",stdout);
    n=read();m=read();
    for(int i=1;i<=n+m-1;i++) y*=i;
    for(int i=1;i<=n;i++){
        ll t=1,l=i,r=i+m-1;
        for(int j=1;j<l;j++) t*=j;
        for(int j=r+1;j<=n+m-1;j++) t*=j;
        x+=t;
    }
    ll g=gcd(x,y);
    printf("%lld\n%lld",x/g,y/g);
}

 

posted @ 2016-11-11 21:48  Candy?  阅读(140)  评论(0编辑  收藏  举报