精神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的点 ...
随机推荐
- HTTP 协议中 URI 和 URL 有什么区别?
HTTP 协议中 URI 和 URL 有什么区别? HTTP = Hyper Text Transfer ProtocolURI = Universal Resource IdentifierURL ...
- c语言实践 统计输入的一串正整数里面奇数和偶数的个数
怎么考虑这个问题. 首先先确定肯定是需要一个变量保存输入的数据的,我们叫它input,最后结果要的是个数,所以需要另外两个变量来保存奇数的个数和偶数的个数. int input int countJ ...
- linux蓝屏时间修改
setterm -blank 2 #/etc/profile里添加这样一句话,可以让屏幕2分钟后没有信号(蓝屏) setterm -blank 0 #/etc/profile里添加这样一句话, ...
- zend studio永久使用的方法
安装时选择试用版,以后每天的剩余天数会减少,找到c盘->用户->administrator删除三个文件(.zend,.zend studio,.zs)即可,.zs往往是隐藏的,这时需要选择 ...
- C# winform中Setting.settings 相关知识点
1.在Settings.settings文件中定义配置字段.包含字段名.类型.范围.值四部分的属性. 字段名.类型和值类似编程中字段的定义一样使用,不再过多的解释.重点讲一下”范围“字段的含义与区别. ...
- JS和JQuery的比较
一. Jquery它是javascript的一个轻量级框架,是对javascript进行封装. 二.JQuery和JS都有加载函数,但表达方式不同. 1.JS中的加载函数: //整个文档加载完毕后执行 ...
- switch case 判断是否为按钮、设置属性 Load Foreach 绑定事件
private void button9_Click(object sender, EventArgs e) { foreach (Control CT in this.Controls) {//判断 ...
- Windows + python + pywinauto 搭建自动化测试环境
最近公司在搞测试, 单纯的人工去测试需要花费太多的人力物力以及时间, 所以准备用Python做一套自动化测试来使用. 本文中使用的是Python3.6.8 和 pywin32-224.win-amd ...
- 一个基于 .NET Core 2.0 开发的简单易用的快速开发框架 - LinFx
LinFx 一个基于 .NET Core 2.0 开发的简单易用的快速开发框架,遵循领域驱动设计(DDD)规范约束,提供实现事件驱动.事件回溯.响应式等特性的基础设施.让开发者享受到正真意义的面向对象 ...
- Setting property 'source' to 'org.eclipse.jst.jee.server:web' did not find a matching property原因
这个问题困扰了好久,虽然只是tomcat的一个警告,但强迫症让我总觉得不舒服,搜索了好多文章才找到知乎上一篇处理的最好的.另外:能找谷哥,尽量不要度娘,太浪费时间. 具体操作如下: 默认情况下,ser ...