精神AC合集 2018.4.3
UESTC炸了,先把看似十分OK(只是过了样例)的代码贴上,修复好后再交上去
594
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int MAXN = 5e4+11;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
typedef long long ll;
// jjjlo
const ll MOD = 1e9+7;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll best[MAXN][103];
int a[MAXN],n,C;
int main(){
while(cin>>n>>C){
memset(best,0x3f,sizeof best);
deque<int> que1,que2;
rep(i,1,n) a[i]=read();
rep(i,1,n) best[1][i]=(i>=a[1]?(i-a[1])*(i-a[1]):INF);
rep(i,2,n){
rep(j,1,a[i]){//ai || deng
if(best[i-1][j]==INF) continue;
while(!que1.empty()&&best[i-1][que1.front()]-C*que1.front()>best[i-1][j]-C*j) que1.pop_front();
que1.push_front(j);
}
rep(j,a[i]+1,100){//gao
if(best[i-1][j]==INF) continue;
while(!que2.empty()&&best[i-1][que2.front()]+C*que2.front()>best[i-1][j]+C*j) que2.pop_front();
que2.push_front(j);
}
rep(j,a[i],100){
if(!que1.empty()) best[i][j]=best[i-1][que1.back()]+C*(j-que1.back())+(j-a[i])*(j-a[i]);
if(!que2.empty()) best[i][j]=min(best[i][j],best[i-1][que2.back()]+C*(que2.back()-j)+(j-a[i])*(j-a[i]));
while(!que2.empty()&&que2.back()<=j+1){
int tmp=que2.back();que2.pop_back();
while(!que1.empty()&&best[i-1][que2.front()]-C*que1.front()>best[i-1][tmp]-C*tmp) que1.pop_front();
que1.push_front(tmp);
}
}
while(!que1.empty()) que1.pop_back();
while(!que2.empty()) que2.pop_back();
}
ll ans=INF;
rep(i,1,100) if(a[n]<=i) ans=min(ans,best[n][i]);
println(ans);
}
return 0;
}
1651
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int MAXN = 1e3+11;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
typedef long long ll;
const ll MOD = 1e9+7;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int G[MAXN][MAXN],n,m;
ll best[2][MAXN][MAXN][2];
int main(){
while(cin>>n>>m){
rep(i,1,n)rep(j,1,m) G[i][j]=read();
memset(best,0,sizeof best);
rep(i,1,n) rep(j,1,m){
best[0][i][j][0]=max(best[0][i][j][0],best[0][i-1][j][0]+G[i][j]);
best[0][i][j][0]=max(best[0][i][j][0],best[0][i][j-1][0]+G[i][j]);
}
rrep(i,n,1) rrep(j,m,1){
best[0][i][j][1]=max(best[0][i][j][1],best[0][i+1][j][1]+G[i][j]);
best[0][i][j][1]=max(best[0][i][j][1],best[0][i][j+1][1]+G[i][j]);
}
rrep(i,n,1) rep(j,1,m){
best[1][i][j][0]=max(best[1][i][j][0],best[1][i+1][j][0]+G[i][j]);
best[1][i][j][0]=max(best[1][i][j][0],best[1][i][j-1][0]+G[i][j]);
}
rep(i,1,n) rrep(j,m,1){
best[1][i][j][1]=max(best[1][i][j][1],best[1][i-1][j][1]+G[i][j]);
best[1][i][j][1]=max(best[1][i][j][1],best[1][i][j+1][1]+G[i][j]);
}
ll ans=-1;
rep(i,1,n) rep(j,1,m){
ll tmp1=best[0][i][j-1][0];//from left
ll tmp2=best[0][i-1][j][0];//from top
ll tmp3=best[0][i][j+1][1];//to right
ll tmp4=best[0][i+1][j][1];// to bottom
// ll t1=max(tmp1+tmp3,tmp1+tmp4);
// ll t2=max(tmp2+tmp3,tmp2+tmp4);
// ll res1=max(t1,t2);
ll rtmp1=best[1][i][j-1][0];//from left
ll rtmp2=best[1][i+1][j][0];//from bottom
ll rtmp3=best[1][i][j+1][1];//to right
ll rtmp4=best[1][i-1][j][1];//to top
// ll rt1=max(rtmp1+rtmp3,rtmp1+rtmp4);
// ll rt2=max(rtmp2+rtmp3,rtmp2+rtmp4);
// ll res2=max(rt1,rt2);
// ans=max(ans,res1+res2);
ll t1=tmp1+tmp3+rtmp2+rtmp4;
ll t2=rtmp1+rtmp3+tmp2+tmp4;//可通过终点的方案(未考虑边界/能否接触<-必能接触,不是强制同步)
if(i==1)continue;//专家1非法
if(j==1)continue;//专家0非法
ans=max(ans,max(t1,t2));
}
println(ans);
}
return 0;
}
1608
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int MAXN = 1e3+11;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
typedef long long ll;
const ll MOD = 1e9+7;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int P[22][22][22],n,x,y,z,zz;
ll dp[1<<21|1];
void get(int t){
x=y=z=zz=-1;
for(int i=0;i<23;i++) if((t>>i)&1){
if(x==-1) x=i;
else if(y==-1) y=i;
else if(z==-1) z=i;
else if(zz==-1) zz=i;
}
}
int main(){
while(cin>>n){
int m=n*(n-1)*(n-2)/6;
rep(i,1,m){
int a=read();
int b=read();
int c=read();
int t=read();
P[a][b][c]=t;
}
memset(dp,0,sizeof dp);
for(int S=0;S<=(1<<n)-1;S++){
get(S);
// cout<<x<<" "<<y<<" "<<z<<endl;
if(z==-1)continue;
for(int S0=S;S0;S0=S&(S0-1)){
get(S0);
if(z==-1)continue;
if(zz!=-1)continue;
dp[S]=max(dp[S],dp[S^S0]+P[x+1][y+1][z+1]);
}
}
println(dp[(1<<n)-1]);
}
return 0;
}
优化一下
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int MAXN = 1e3+11;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
typedef long long ll;
const ll MOD = 1e9+7;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int P[22][22][22],n,x,y,z,zz;
bool vis[22];
ll dp[1<<21|1];
void get(int t){
x=y=z=zz=-1;
for(int i=0;i<23;i++) if((t>>i)&1){
if(x==-1) x=i;
else if(y==-1) y=i;
else if(z==-1) z=i;
else if(zz==-1) zz=i;
}
}
ll DP(int S){
if(~dp[S]) return dp[S];
ll ans=0;
int i,flag=0;
for(i=0;i<n-2;i++) if((S>>i)&1){
flag=1;break;
}
if(!flag)return dp[S]=0;
// for(int i=0;i<n-2;i++){
// if((S>>i)&1){
for(int j=i+1;j<n-1;j++){
if((S>>j)&1){
for(int k=j+1;k<n;k++){
if((S>>k)&1){
ans=max(ans,DP(S^(1<<i)^(1<<j)^(1<<k))+P[i+1][j+1][k+1]);
}
}
}
}
// }
// }
return dp[S]=ans;
}
int main(){
while(cin>>n){
int m=n*(n-1)*(n-2)/6;
rep(i,1,m){
int a=read();
int b=read();
int c=read();
int t=read();
P[a][b][c]=t;
}
// memset(dp,0,sizeof dp);
// for(int S=0;S<=(1<<n)-1;S++){
// get(S);
// // cout<<x<<" "<<y<<" "<<z<<endl;
// if(z==-1)continue;
// for(int S0=S;S0;S0=S&(S0-1)){
// get(S0);
// if(z==-1)continue;
// if(zz!=-1)continue;
// dp[S]=max(dp[S],dp[S^S0]+P[x+1][y+1][z+1]);
// }
// } //太慢了
memset(dp,-1,sizeof dp);
println(DP((1<<n)-1));
}
return 0;
}
1134
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int MAXN = 5e2+11;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
typedef long long ll;
const ll MOD = 1e9+7;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll dp[11][11][1<<11|1];
int G[11][11];
int main(){
rep(i,1,10) rep(j,1,10) G[i][j]=read();
memset(dp,0x3f,sizeof dp);
// rep(i,0,(1<<10)-1) dp[1][0][i]=dp[0][0][i]=dp[0][1][i]=0;
dp[1][1][1<<G[1][1]]=G[1][1];
rep(i,1,10) rep(j,1,10){
for(int S=0;S<=(1<<10)-1;S++){
int t=1<<G[i][j];
if((S>>G[i][j])&1){
dp[i][j][S]=min(dp[i][j][S],min(dp[i-1][j][S^t],dp[i][j-1][S^t])+G[i][j]);//que
dp[i][j][S]=min(dp[i][j][S],min(dp[i-1][j][S],dp[i][j-1][S])+G[i][j]);//buque
}
else{
dp[i][j][S^t]=min(dp[i][j][S^t], min(dp[i-1][j][S],dp[i][j-1][S])+G[i][j] );//que
}
}
}
println(dp[10][10][(1<<10)-1]);
return 0;
}
精神AC合集 2018.4.3的更多相关文章
- SAP成都研究院2018年总共87篇技术文章合集
2018年很快就要结束了.Jerry在2017年年底准备开始写这个公众号时,给自己定的目标是:2018年至少保证每周发布一篇高质量的文章.如今2018年就快过去了,高质量与否需要大家来反馈,至少从量上 ...
- 【开发必备】2018最新中国国内可用API合集
中国国内可用API合集 笔记 OneNote - OneNote支持获取,复制,创建,更新,导入与导出笔记,支持为笔记添加多媒体内容,管理权限等.提供SDK和Demo. 为知笔记 - 为知笔记Wind ...
- id0-rsa WP合集
忙里偷闲做做题wwwwwwwwwwwww Intro to Hashing Intro to PGP Hello PGP Hello OpenSSL Intro to RSA Caesar Hello ...
- [题解+总结]NOIP动态规划大合集
1.前言 NOIP2003-2014动态规划题目大合集,有简单的也有难的(对于我这种动态规划盲当然存在难的),今天就把这些东西归纳一下,做一个比较全面的总结,方便对动态规划有一个更深的理解. 2.NO ...
- Android中的对话框AlertDialog使用技巧合集-转载
Android中的对话框AlertDialog使用技巧合集 文章来自:http://blog.csdn.net/blue6626/article/details/6641105 今天我用自 ...
- 11、js 数组详细操作方法及解析合集
js 数组详细操作方法及解析合集 前言 在开发中,数组的使用场景非常多,平日中也涉及到很多数组的api/相关操作,一直也没有对这块内容进行一块整理总结,很多时候就算用过几次这个api,在开发中也很容易 ...
- 【强大精美的PS特效滤镜合集】Alien Skin Eye Candy for Mac 7.2.2.20
[简介] Alien Skin Eye Candy for Mac 7.2.2 版本,支持最新的PhotoShop CC 2019.2018等版本,这是一款强大酷炫的PS特效滤镜合集,具有32种滤镜和 ...
- 精彩看点 | GIAC大会PPT+视频合集全量放送!
GIAC是中国互联网技术领域的行业盛事,每年从互联网架构最热门的系统架构设计.人工智能.机器学习.工程效率.区块链.分布式架构等领域甄选前沿有典型代表的技术创新及研发实践的架构案例,分享他们在本年度最 ...
- Codeforces - tag::data structures 大合集 [占坑 25 / 0x3f3f3f3f]
371D 小盘子不断嵌套与大盘子,最后与地面相连,往里面灌水,溢出部分会往下面流,求每次操作时当前的盘子的容量 其实这道题是期末考前就做好了的.. 链式结构考虑并查集,然后没了(求大佬解释第一个T的点 ...
随机推荐
- Python基础入门-While循环
讲完了for循环我们继续来看第二个循环,那就是while循环,while循环和for循环虽然都是循环,但是有着本质的不同.我们先来看下她们之间的区别和联系: While循环和for循环区别: 1.fo ...
- C6678 srio communication via Switch
First, I don't often give praise for support but I must say Travis, Karthik and Derek from TI have b ...
- (转)【前端模板之路】一、重构的兄弟说:我才不想看你的代码!把HTML给我交出来!
原文地址:http://www.cnblogs.com/chyingp/archive/2013/06/30/front-end-tmplate-start.html 写在前面 随着前端领域的发展和社 ...
- 编写高质量代码改善C#程序的157个建议——建议4: TryParse比Parse好
建议4: TryParse比Parse好 如果注意观察除string外的所有基元类型,会发现它们都有两个将字符串转型为本身的方法:Parse和TryParse.以类型double为例,这两个方法最简单 ...
- [Lua快速了解一下]Lua的语法
-注释 -- 两个减号是行注释 -块注释 --[[ 这是块注释 这是块注释 --]] -变量 Lua的数字只有double型,64bits, Lua的字符串string支持双引号或者单引号 以下例子会 ...
- .net连接eDirectory,需要安全连接的解决方案
用C#连接eDirectory ,提示: “这个请求需要一个安全的连接.” 解决办法,eDirectory禁用TLS(这方法比较猥琐) ssh连接到eDirectory服务器上,执行: ldapcon ...
- delphi json用法
用法:uses Superobject, Sperjsondelphi里有json单元. procedure TForm2.SuperObjectClick(Sender: TObject); var ...
- JS 换行写法
var populatePullUpHtml = function (id) { var html = '<div id="' + id + '" class="' ...
- VS Code基本使用
1. Activity Bar 1.1 Explorer 1.1.1. OPEN EDITORS 所有在右侧编辑区打开的文件列表 1.1.2 {PROJECTNAME} 某个文件夹下的文件树 1.2 ...
- iOS APP打包上传到APPstore的最新步骤
一.前言: 作为一名iOS开发者,把辛辛苦苦开发出来的App上传到App Store是件必要的事.但是很多人还是不知道该怎么上传到App Store上 下面就来详细讲解一下具体流程步骤. 二.准备: ...