19-10-27-S
作者太巨辣!
%%%乔猫
好。
ZJ一下:
哭笑不得。
T1直接审错题(没发现题目里那个憨P的更新限制),然后直接跑了$\mathsf{SPFA}$,然后我又发现了。以为我死了,结果手玩一下发现……那句话没有用……
试图卡一下$\mathsf{SPFA}$但是发现卡不掉,我想这么水一题卡毛线$\mathsf{SPFA}$,于是就扔掉了。
T2打了贪心错解组合版,但是自己大力$\text{hack}$完后就以为死了,后来还有$30pts$,作者太友好了(感动
T3发现直接在角度上维护即可,于是码完,然后发现给的端点真不友好,不是左上右下,而是左下右上,后来还被卡精了$\text{kuku}$
这是TJ:
T1:
名正言顺的AC了。
作者没有构造卡$\mathsf{SPFA}$的数据……
很不明白网格图上咋卡……
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 555 using namespace std; const int mx[]={0, 0,1,-1},
my[]={1,-1,0, 0};
typedef pair<int,int> pii;
template<typename T>
class Myqueue{
T A[N*N*100];
int f,b;
public:
Myqueue(){f=b=0;}
void clear(){f=b=0;}
void push(const T k){A[b++]=k;}
void pop(){f++;}
T front(){return A[f];}
bool empty(){return f==b;}
};
Myqueue<pii>q;
int lines,cols;
int tps[N][N],lps[N][N];
int fix,fiy;
bool inq[N][N];
void pour(){
for(int i=1;i<=3;i++){
for(int j=1;j<=cols;j++){
cout<<"----";
}
if(i!=3)cout<<"+";
}
puts("");
for(int i=1;i<=lines;i++){
for(int j=1;j<=cols;j++)
printf("%4d",lps[i][j]);
cout<<"|";
for(int j=1;j<=cols;j++)
printf("%4d",tps[i][j]);
cout<<"|";
for(int j=1;j<=cols;j++)
printf("%4d",inq[i][j]);
puts("");
}
/* puts("------Inqueue----------");
for(int i=1;i<=lines;i++){
for(int j=1;j<=cols;j++){
printf("%4d",inq[i][j]);
}puts("");
}*/
}
inline bool in_b(int x,int y){
return x>=1&&x<=lines&&y>=1&&y<=cols;
}
inline bool in_b(pii ps){
return in_b(ps.first,ps.second);
}
void bfs(int x,int y){//?
q.push(make_pair(x,y));
inq[x][y]=1;
while(!q.empty()){
int fx=q.front().first,
fy=q.front().second;
// cout<<fx<<" "<<fy<<endl;
q.pop();
if(q.empty())q.clear();
inq[fx][fy]=0;//?Double UPD??
for(int i=0;i<4;i++){
int tx=fx+mx[i],
ty=fy+my[i];
if(in_b(tx,ty) && lps[tx][ty]<lps[fx][fy]-tps[tx][ty]){
lps[tx][ty]=lps[fx][fy]-tps[tx][ty];
if(!inq[tx][ty]){
q.push(make_pair(tx,ty));
inq[tx][ty]=1;
}
}
}
// pour();
}
}
int main(){
// freopen("neworld.in" ,"r",stdin);\
freopen("neworld.out","w",stdout);
int a,b,c;
scanf("%d%d",&lines,&cols);
for(int i=1;i<=lines;i++)
for(int j=1;j<=cols;j++)
scanf("%d",&tps[i][j]);
scanf("%d%d%d%d%d",&a,&b,&c,&fix,&fiy);
lps[a][b]=c;
bfs(a,b);
printf("%d\n",lps[fix][fiy]);
// cerr<<clock()<<endl;
}
叫$\mathsf{BFS}$但是是$\mathsf{SPFA}$
T2:
状压即可,细节还行。
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio> //#include "debug.h" #define N 111
#define M 10
#define S (1<<9)+10 using namespace std; int dp[N][S],mp[N];
int lines,cols,maxs; inline int lowbit(int x){
return x&(-x);
}
inline int count(int x){
int n_1=0;
while(x){
x-=lowbit(x);
n_1++;
}
return n_1;
}
bool is_ok(int i1,int pos1){
for(int i=1;i<=cols;i++){
int j=1<<(i-1);
if(j&pos1){
if(!(j&mp[i1]))return false;
}
}
for(int i=1;i<=cols;i++){
int j=1<<(i-1);
if((j&mp[i1])&&(!((j>>1)&mp[i1]))){
if(!(j&pos1))return false;
}
}
return true;
}
int get_merge(int i1,int pos1,int i2,int pos2){
int dat=0;
for(int i=1;i<=cols;){
int j=1<<(i-1);
// cout<<i<<" Outout"<<endl;
if((pos1&j) && (pos2&j)){
int k=i+1,l=1<<(k-1);
while(1){
//cerr<<k<<endl;
if(k>cols){
dat++;
break;
}
if(((!(l&mp[i1])) || (l&pos1)) && \
((!(l&mp[i2])) || (l&pos2))){
// puts("All WA");
dat++;
break;
}
else if( (l&mp[i1])&&(l&mp[i2])&&(!(l&pos1))&&(!(l&pos2)) ){
//puts("One WA");
k++,l=1<<(k-1);
}
else
break;
//puts("Contined");
}
i=k;
continue;
}
i++;
}
// cout<<"Res:"<<dat<<endl;
return dat;
}
int main(){
ios_base::sync_with_stdio(false);
int a;
cin>>lines>>cols;
maxs=(1<<cols)-1;
for(int i=1;i<=lines;i++){
for(int j=1;j<=cols;j++){
cin>>a;
mp[i]|=a<<(j-1);
}
}
// for(int i=1;i<=lines;i++)\\
cerr<<bin(mp[i],cols)<<endl;
memset(dp,0x3f,sizeof dp);
for(int s=0;s<1<<cols;s++){
if(is_ok(1,s)){
dp[1][s]=count(s);
// cerr<<dp[1][s]<<" "<<bin(s,cols)<<endl;
}
}
for(int i=2;i<=lines;i++){
for(int s=0;s<1<<cols;s++){
if(!is_ok(i,s))continue;
for(int t=0;t<1<<cols;t++){
if(!is_ok(i-1,t))continue;
//cerr<<"Mp["<<i<<"]="<<bin(mp[i],cols)\
<<" S:"<<bin(s,cols)<<" "\
<<"Mp["<<i-1<<"]="<<bin(mp[i-1],cols)\
<<" T:"<<bin(t,cols)<<endl;
int val=count(s)-get_merge(i,s,i-1,t);
// cout<<"val:"<<get_merge(i,s,i-1,t)<<endl;
dp[i][s]=min(dp[i][s],
dp[i-1][t]+val);
// cout<<"dp["<<i<<"]["<<bin(s,cols)<<"]="<<dp[i][s]<<endl;
}
}
}
int ans=INT_MAX;
for(int s=0;s<1<<cols;s++)
if(is_ok(lines,s))
ans=min(ans,dp[lines][s]);
cout<<ans<<endl;
}
T3:
不会!
19-10-27-S的更多相关文章
- 背水一战 Windows 10 (27) - 控件(文本类): TextBlock
[源码下载] 背水一战 Windows 10 (27) - 控件(文本类): TextBlock 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) TextBlock 示例 ...
- 第15次Scrum会议(10/27)【欢迎来怼】
一.小组信息 队名:欢迎来怼 小组成员 队长:田继平 成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/27 17:20~17:45,总计25min. 地点 ...
- JZOJ 4269. 【NOIP2015模拟10.27】挑竹签
4269. [NOIP2015模拟10.27]挑竹签 (File IO): input:mikado.in output:mikado.out Time Limits: 1000 ms Memory ...
- Ubuntu 19.10 发布 | 云原生生态周报 Vol. 24
作者 | 木苏.进超.冬岛.元毅.心水.衷源 业界要闻 1.云原生编程语言 Pulumi 1.0 pulumi ,一款中立的开源云开发平台,Pulumi 支持多语言.混合云环境.完全可扩展.初期支持 ...
- [Linux] 在 Ubuntu 19.10 上开启 SSH 服务并允许远程登录
在 Ubuntu 19.10 上安装 SSH,并开启服务 0.检查并确认系统当前是否已安装SSH: sudo ps -e | grep ssh 如果只有 ssh-agent 说明 ssh-server ...
- [Linux] 树莓派 4B 安装 Ubuntu 19.10 (Eoan Ermine) IOT 版
硬件:Raspberry Pi 4B系统:Ubuntu 19.10 (Eoan Ermine) for IOT官网:https://ubuntu.com/download/iot/raspberry- ...
- Ubuntu 19.10 安装 jupyter
安装pip3 ubuntu 19.10 已经没有python了,取代的是python3. 执行sudo apt install python3-pip安装pip3 安装jupyter 执行sudo p ...
- Ubuntu 19.10将使用GCC 9作为默认编译器
作为我们这一周期一直期待的变化,Ubuntu 19.10升级到GCC 9作为GCC 8的默认系统编译器. Ubuntu 19.10(和Ubuntu 20.04 LTS)将使用GCC 9 stable作 ...
- Unix 网络编程卷一源码编译踩坑记录 ubtutu 19.10
在阅读unpv1时运行源代码的环境配置,这里简单记录一下 源代码里的README 写得挺详细的,但是在Linux 系统的下还没没办法直接编译通过的, 这里我使用的是ubuntu 19.10(在腾讯云1 ...
- 程序员的 Ubuntu 19.10 配置与优化指南
原文地址:程序员的 Ubuntu 19.10 配置与优化指南 0x00 环境 CPU: Intel Core i9-9900k GPU: GeForce RTX 2070 SUPER RAM: DDR ...
随机推荐
- Springboot-WebSocket获取HttpSession问题
换了新工作,第一个任务就是和这个有关,以前没接触过,没办法,各种度娘.谷哥,大部分都是只言片语,要么就是特定的配置环境还不贴配置--,踩坑无数, 遂整理成笔记 WebSocket协议 WebSocke ...
- eclispe 创建maven 项目:Could not resolve archetype org.apache.maven.archetypes
昨天新装eclispe 后,创建maven工程后出现 Could not resolve archetype org.apache.maven.archetypes:maven-archetype-q ...
- 【POJ】3278 Catch That Cow
题目链接:http://poj.org/problem?id=3278 题意:有一头奶牛跑到了K的位置,农夫在N的位置,求最短抓到奶牛的时间. 农夫有两种移动方式. 1.步行:一分钟内从x->x ...
- CentOS增加swap分区大小
来自:http://www.centoscn.com/CentOS/Intermediate/2014/0222/2446.html 1. 查看当前分区情况 free -m 2. 增加 swap 大小 ...
- Spark与Hadoop的对比
- CF850E Random Elections
题意:一共有n个人,要在三个人中选prefer,一开始他们心中都会想好他们的排名(共6种),之后给出的判断不会矛盾.规则如下:一共有三轮,分别是a->b,b->c,c->a,每个人选 ...
- 【JZOJ1667】【BZOJ1801】【luoguP2051】中国象棋
description 在N行M列的棋盘上,放若干个炮可以是0个,使得没有任何一个炮可以攻击另一个炮.请问有多少种放置方法?中国象棋中炮的行走方式大家应该很清楚吧. analysis \(DP\),容 ...
- 云时代IDC自动化运维的几大神器
云时代IDC自动化运维的几大神器 2016年09月18日 10:27:41 天府云创 阅读数:1715 版权声明:本文为EnweiTech原创文章,未经博主允许不得转载. https://blog ...
- sass与less的区别?Stylus又是啥?
现在写样式大家基本上都会用上CSS预处理器,而比较流行的预处理器就是这三位老哥了Less.Sass 和 Stylus: 在这之前,我们先了解一点,sass和scss有什么区别? SCSS 是 Sass ...
- VS2015遇到的自带报表的问题
1.设计报表时候,没有“报表数据”工具,直接在报表设计那里按ALT+CTRL+D 2.设计报表时候有时候找不到这些按钮,只需要重置窗口布局就行了.