• Day2代码


      1 #include<cstdio>
      2 #include<cstring>
      3 #include<cmath>
      4 #include<algorithm>
      5 #define lli long long int 
      6 using namespace std;
      7 const lli MAXN=401;
      8 const lli INF=0x7ffff;
      9 inline void read(lli &n)
     10 {
     11     char c=getchar();n=0;bool flag=0;
     12     while(c<'0'||c>'9')    c=='-'?flag=1,c=getchar():c=getchar();
     13     while(c>='0'&&c<='9')    n=n*10+c-48,c=getchar();n=flag==1?-n:n;
     14 }
     15 lli n,m,s,k;
     16 struct C
     17 {
     18     lli ID;
     19     lli score;
     20 }sj[MAXN];
     21 bool how[MAXN];
     22 lli ans=-1;
     23 lli impro[MAXN];
     24 lli comp(const C &a,const C &b)
     25 {
     26     return a.score<b.score;
     27 }
     28 lli now=0;
     29 void pd()
     30 {
     31     memset(impro,0,sizeof(impro));
     32     for(lli i=1;i<=m;i++)
     33         if(how[i])
     34             impro[sj[i].ID]+=(-sj[i].score);
     35     for(lli i=1;i<=n;i++)
     36         if(impro[i]<k)
     37             return ;
     38     lli cur=0;
     39     for(lli i=1;i<=n;i++)
     40         cur+=impro[i];
     41     ans=max(ans,cur);
     42 }
     43 void dfs(lli now,lli spend)
     44 {
     45     if(now==m+1)    {    pd();    return ;    }
     46     if(spend<s)
     47     {
     48         how[now]=1;
     49         dfs(now+1,spend+1);// tou
     50         how[now]=0;    
     51     }
     52     how[now]=0;
     53     dfs(now+1,spend);//bu tou 
     54 }
     55 void check()
     56 {
     57     ans=0;
     58     for(lli i=1;i<=m;i++)
     59     {
     60         if(impro[sj[i].ID]<k&&sj[i].score<0)
     61             if(now<s)
     62             {    impro[sj[i].ID]+=(-sj[i].score);    now++;    
     63                 ans+=(-sj[i].score);    sj[i].score=INF;     }    
     64             else
     65             {    printf("-23333333");    exit(0);    }
     66         else    continue;
     67     }
     68     for(lli i=1;i<=n;i++)
     69         if(impro[i]<k)
     70             {    printf("-23333333");    exit(0);    }
     71 
     72     sort(sj+1,sj+m+1,comp);
     73     for(lli i=1;i<=m;i++)
     74         if(now<s&&sj[i].score!=INF&&sj[i].score<0)
     75             ans+=(-sj[i].score),    now++;
     76     printf("%lld",ans);
     77 }
     78 int main()
     79 {
     80     freopen("express.in","r",stdin);
     81     freopen("express.out","w",stdout);
     82     read(n);read(m);read(s);read(k);
     83     for(lli i=1;i<=m;i++)
     84     {
     85         read(sj[i].ID);read(sj[i].score);
     86         sj[i].score=2-sj[i].score;
     87     }
     88     if(n<=20)
     89     {
     90         dfs(0,0);
     91         if(ans==-1)    printf("-23333333");
     92         else printf("%lld",ans);    
     93     }
     94     else
     95     {
     96         sort(sj+1,sj+m+1,comp);
     97         check();
     98     }
     99     return 0;
    100 }
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 const int MAXN=401;
     8 inline void read(int &n)
     9 {
    10     char c=getchar();n=0;bool flag=0;
    11     while(c<'0'||c>'9')    c=='-'?flag=1,c=getchar():c=getchar();
    12     while(c>='0'&&c<='9')    n=n*10+c-48,c=getchar();n=flag==1?-n:n;
    13 }
    14 string a;
    15 void work(int bg,int ed)
    16 {
    17     string b;    int now=0;
    18     for(int i=ed-1;i>bg;i--)    
    19         if(a[i]=='(')    b=b+')';
    20         else if(a[i]==')')    b=b+'(';
    21         else b=b+a[i];
    22     for(int i=bg+1;i<ed;i++)    a[i]=b[now++];    a[bg]='$';a[ed]='$';
    23 }
    24 int main()
    25 {
    26     freopen("unknown.in","r",stdin);
    27     freopen("unknown.out","w",stdout);
    28     cin>>a;
    29     int la=a.length();
    30     int now=0;
    31     int bg=0,ed=0;
    32     while(a.find('(')!=a.npos)
    33     {
    34         for(int i=0;i<a.length();i++)
    35         {
    36             if(a[i]=='(')    {    if(now==0)    bg=i;                now++;    }
    37             if(a[i]==')')    {    if(now==1)    ed=i,work(bg,ed);    now--;    }
    38         }    
    39     //    cout<<a<<endl;
    40     }
    41     for(int i=0;i<=a.length();i++)
    42         if(a[i]!='$')    cout<<a[i];
    43     return 0;
    44 }
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<algorithm>
     5 using namespace std;
     6 const int MAXN=438; 
     7 const int INF=100001;
     8 inline void read(int &n)
     9 {
    10     char c=getchar();n=0;bool flag=0;
    11     while(c<'0'||c>'9')    c=='-'?flag=1,c=getchar():c=getchar();
    12     while(c>='0'&&c<='9')    n=n*10+c-48,c=getchar();n=flag==1?-n:n;
    13 }
    14 int map[438][438];
    15 int n,m,k;
    16 int main()
    17 {
    18     freopen("prison.in","r",stdin);
    19     freopen("prison.out","w",stdout);
    20     read(n);read(m);read(k);
    21     for(int i=1;i<=m;i++)
    22     {
    23         int x,y;read(x);read(y);
    24         map[x][y]=1;map[y][x]=1;
    25     }
    26     if(n==2)
    27     {
    28         if(map[1][2])
    29         {
    30             if(k==0)    printf("2");
    31             else printf("1");
    32         }
    33         else printf("1");
    34     }
    35     else
    36     {
    37         printf("%d",rand()%n);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    spring + junit 测试
    备份mysql数据库
    JAVA访问Zabbix API
    pro git 读书笔记 3 Git 分支
    pro git 读书笔记 1
    pro git 读书笔记 2
    溢出和剪裁,可见性
    html 与 jsp 文件格式区别
    Eclipse 的 CheckStyle 插件
    【转】单元测试覆盖率
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/7535555.html
Copyright © 2020-2023  润新知