Acme Corporation UVA - 11613 费用流

Acme Corporation UVA - 11613 费用流

Code:

#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=500;
const int INF=10000000+23666;
typedef long long ll;
int s,t,n;
struct Edge{
	int from,to,cost;
	ll cap;
	Edge(int u,int v,ll c,int f):from(u),to(v),cap(c),cost(f){}
};
struct MCMF{
    vector<Edge>edges;
    vector<int>G[maxn];
    ll d[maxn],inq[maxn],a[maxn],flow2[maxn];
    queue<int>Q;
    ll ans=0;
    int flow=0;
    void init(){
    	   memset(a,0,sizeof(a));
    	   edges.clear();
    	   for(int i=0;i<maxn;++i)G[i].clear();
    	   ans=0,flow=0;
    }
    void addedge(int u,int v,int c,int f){
    	edges.push_back(Edge(u,v,c,f));    //正向弧
    	edges.push_back(Edge(v,u,0,-f));   //反向弧
    	int m=edges.size();
    	G[u].push_back(m-2);
    	G[v].push_back(m-1);
    }
    int SPFA(){
    	for(int i=0;i<=n;++i)d[i]=INF,flow2[i]=INF;
    	memset(inq,0,sizeof(inq));int f=INF;
    	d[s]=0,inq[s]=1;Q.push(s);
        while(!Q.empty()){
        	int u=Q.front();Q.pop();inq[u]=0;
        	int sz=G[u].size();
        	for(int i=0;i<sz;++i){
                  Edge e=edges[G[u][i]];
                  if(e.cap>0&&d[e.to]>d[u]+e.cost){
                      a[e.to]=G[u][i];
                      d[e.to]=d[u]+e.cost;
                      flow2[e.to]=min(flow2[u],e.cap);
                      if(!inq[e.to]){inq[e.to]=1;Q.push(e.to);}
                  }
        	}
        }
        if(d[t]>=0)return 0;
        f=flow2[t];
        flow+=f;
        int u=edges[a[t]].from;
        edges[a[t]].cap-=f;
        edges[a[t]^1].cap+=f;
        while(u!=s){
        	edges[a[u]].cap-=f;
        	edges[a[u]^1].cap+=f;
        	u=edges[a[u]].from;
        }
        ans+=(ll)(d[t]*f);
        return 1;
    }
    ll maxflow(){
        while(SPFA());
        return -ans;
    }
}op;
int main()
{
	int T;scanf("%d",&T);
	for(int cas=1;cas<=T;++cas)
	{
          op.init();int cnt=0;
		int m,I;scanf("%d%d",&m,&I);
		s=0,n=2*m+1,t=n;
		for(int i=1;i<=m;++i){
			cnt+=2;
		     int mi,ni,pi,si,E;
		     scanf("%d%d%d%d%d",&mi,&ni,&pi,&si,&E);
               op.addedge(s,cnt,ni,mi);
               op.addedge(cnt-1,t,si,-pi);
               int a=cnt-1;
               for(int j=0;j<=E&&a<t;++j){
                    op.addedge(cnt,a,INF,j*I);
                    a+=2;
               }
          }
          printf("Case %d: %lld\n",cas,op.maxflow());  
	}
	return 0;
}

  

posted @ 2019-02-12 23:50 EM-LGH 阅读( ...) 评论( ...) 编辑 收藏
好的,下面是一个使用 acme-client-php 库实现 ACME 协议自动签发证书的示例代码: ```php use AcmePhp\Core\AcmeClient; use AcmePhp\Core\Protocol\Challenge; use AcmePhp\Ssl\Certificate; use AcmePhp\Ssl\CertificateRequest; use AcmePhp\Ssl\PrivateKey; use AcmePhp\Ssl\Signer\CertificateRequestSigner; use AcmePhp\Ssl\Signer\DataSigner; use AcmePhp\Ssl\Signer\SignerFactory; use AcmePhp\Ssl\Generator\KeyPairGenerator; use AcmePhp\Ssl\Parser\KeyParser; use AcmePhp\Ssl\Parser\CertificateParser; use AcmePhp\Ssl\Parser\CertificateRequestParser; // ACME 服务端的 API 地址 $serverUrl = 'https://acme-v02.api.letsencrypt.org/directory'; // 要签发证书的域名列表 $domains = ['example.com', 'www.example.com']; // 创建一个用于存储证书和私钥的目录 $storagePath = '/path/to/storage'; if (!file_exists($storagePath)) { mkdir($storagePath, 0777, true); } // 创建一个私钥 $keyPairGenerator = new KeyPairGenerator(); $privateKey = $keyPairGenerator->generatePrivateKey(); // 创建 ACME 客户端 $acmeClient = new AcmeClient($serverUrl, $privateKey, $storagePath); // 获取 ACME 服务端提供的签发证书所需的验证数据 $authorizationChallenges = $acmeClient->requestAuthorizationChallenges($domains); // 在域名的 DNS 记录中添加验证数据 foreach ($authorizationChallenges as $authorizationChallenge) { if ($authorizationChallenge->getType() === Challenge::TYPE_DNS) { $dnsRecordName = '_acme-challenge.' . $authorizationChallenge->getDomain(); $dnsRecordValue = $authorizationChallenge->getPayload(); // TODO: 将 $dnsRecordName 和 $dnsRecordValue 写入 DNS 记录 } } // 等待 DNS 记录生效 sleep(30); // 向 ACME 服务端验证验证数据 $acmeClient->verifyAuthorizationChallenges($authorizationChallenges); // 生成证书请求文件 $certificateRequest = new CertificateRequest($domains, $privateKey); $certificateRequestSigner = new CertificateRequestSigner(new DataSigner(SignerFactory::create()), new KeyParser()); $certificateRequestPem = $certificateRequestSigner->sign($certificateRequest)->getPEM(); // 向 ACME 服务端申请证书 $certificatePem = $acmeClient->requestCertificate($certificateRequestPem); // 解析证书和私钥 $certificateParser = new CertificateParser(); $certificate = $certificateParser->parse($certificatePem); $privateKeyParser = new KeyParser(); $privateKey = $privateKeyParser->parse($privateKey->toPem()); // 将证书和私钥保存到文件中 $certificatePath = $storagePath . '/certificate.pem'; $privateKeyPath = $storagePath . '/private-key.pem'; file_put_contents($certificatePath, $certificate->toPem()); file_put_contents($privateKeyPath, $privateKey->toPem()); // 打印证书信息 print('Certificate:\n'); print($certificate->toPem()); print("\n"); // 打印私钥信息 print('Private key:\n'); print($privateKey->toPem()); print("\n"); ``` 注意,这只是一个示例代码,需要根据自己的实际情况进行修改。特别是 DNS 记录的操作需要根据自己的 DNS 服务商进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值