D.Distinctive Character

看到样例,第一个反应贪心。先写了个按这一位1和0的数目多少,确定0还是1的东西。感觉不够真,又写了个尽量加到相似的比较小的串上的贪心。在和前边的那个组合一下,换了换顺序。。。好吧就过了13组样例。。。正解如下:考虑如何求出,所有2^k个状态与这n个串的最大相似度。起初的n个串的答案显然为k,那改变一个位置,相似度就改变为k-1,对于一个状态,越早算出来的相似度,越大,那么就可以直接bfs求出所有状态的最大相似度了。答案就是取最小值的状态。

#include <bits/stdc++.h>
#define mem(W) memset(W,0,sizeof(W))
using namespace std;
int n, k, a[1<<23], b[1<<23];
char s[25];
int q[1<<23],l=0,r=0;
int main(){scanf("%d%d",&n,&k);for(int i=0;i<(1<<k);++i)b[i]=-1;for(int i=1;i<=n;++i) {scanf(" %s",s);for(int j=0;j<k;++j) a[i]=a[i]*2+(s[j]-'0');q[r]=a[i];++r;b[a[i]]=k;}while(l<r){int S=q[l]; ++l;for(int i=0;i<k;++i){if(b[S^(1<<i)]==-1){b[S^(1<<i)]=b[S]-1;q[r]=S^(1<<i); ++r;}}}int MN=10000,ans=0;for(int i=0;i<(1<<k);++i){if(MN>b[i]){MN=b[i];ans=i;}}for(int i=k-1;i>=0;--i)printf("%d",!!(ans&(1<<i)));puts("");
}

E.Emptying the Baltic 

bfs暴搜的做法很显然,一直搜到所有位置都无法流向周围的格子为止,但是会tle。考虑剪枝:1)水位低的地方,不能流向高的地方;2)没有水也不能流了;3)最重要的一个剪枝/贪心,我们尽量先去从当前水位比较高的地方搜,用优先队列可以解决。(读题能力好差。。。

#include <cstdio>
#include <queue>
#define rep(i,a,b) for(int i=a;i<=b;++i)
typedef long long ll;
const int N = 550;
inline int read() {char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;
}
using namespace std;
int dx[]={0, 0, 1, 1, -1, -1, 1, -1};
int dy[]={1,-1, 0,-1, 0,   1, 1, -1};
int n, m, xs, ys;
ll mp[N][N], h[N][N];
struct node{int x,y;bool operator < (const node a) const {return h[a.x][a.y] < h[x][y];}node(){}node(int a,int b){x=a;y=b;}
};
inline int inb(int x,int y) {if(x>n||x<1||y>m||y<1)return 0;return 1;
}
inline ll solve(node e,node s){ll t;if(mp[s.x][s.y] >= h[e.x][e.y]) {t=h[s.x][s.y]-mp[s.x][s.y];h[s.x][s.y]-=t;return t;}else {t=h[s.x][s.y]-h[e.x][e.y];h[s.x][s.y]-=t;return t;}return t;
}inline ll bfs(int sx, int sy) {ll ans=0;priority_queue<node> q;q.push(node(sx,sy));ans += (-mp[sx][sy]);h[sx][sy]=mp[sx][sy];while(!q.empty()) {node u=q.top();q.pop();rep(i,0,7) {int tx=u.x+dx[i], ty=u.y+dy[i];if(!inb(tx,ty)||mp[tx][ty]>=0||h[tx][ty] <= h[u.x][u.y])continue;if(h[tx][ty]==mp[tx][ty]) continue;ll tmp=solve(u,node(tx,ty));ans+=tmp;q.push(node(tx,ty));}}return ans;
}
int main() {n=read(),m=read();rep(i,1,n)rep(j,1,m)mp[i][j]=read();xs=read(),ys=read();printf("%lld\n", bfs(xs,ys));
}

G. Galactic Collegiate Programming Contest

用数据结构维护比1队排名靠前的队伍。一眼考虑用优先队列加数组标记,感觉删除的复杂度就没有保证,状态本身就多,还额外加了一些,肯定会T,就没写。然后,考虑用set删除操作就很方便,然而还是T了。(于是膜了题解。。。还学了很多神奇的操作%%%)用multiset的话,有很多重复的值,时间就更优秀了。

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
const int N = 1e5 + 100;
typedef long long ll;
using namespace std;
struct node{int x,y;node(){}node(int a,int b){x=a;y=b;}bool operator < (const node a)const {if(a.y!=y) return y > a.y;return x < a.x;}
};
multiset<node> s;
int n,m,t,p,a[N],b[N];
int main() {scanf("%d%d",&n,&m);rep(i,1,m) {scanf("%d%d",&t,&p);if(t!=1) {if(node(a[t],b[t]) < node(a[1],b[1])) s.erase(s.find(node(a[t],b[t])));a[t]+=p;++b[t];s.insert(node(a[t],b[t]));}else {a[t]+=p;++b[t];}while(!s.empty()&&!(*--s.end()<node(a[1],b[1]))) s.erase(--s.end());printf("%d\n",s.size()+1);}
}

转载于:https://www.cnblogs.com/RRRR-wys/p/9086143.html

2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)相关推荐

  1. 2018 ACM ICPC Arabella Collegiate Programming Contest A

    Multiplication operation is not always easy! For example, it is hard to calculate 27 × 20 using your ...

  2. A - Multiplication Dilemma (思维)( 2018 ACM ICPC Arabella Collegiate Programming Contest)

    滴答滴答---题目链接 Multiplication operation is not always easy! For example, it is hard to calculate 27 × 2 ...

  3. 2016-2017 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2016)题解

    2016-2017 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2016) A - Artwork 题目描述: 给定N*M的网格,给出Q次 ...

  4. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) - 4.28

    赛后补了几道 赛中我就写了两个... A - Altruistic AmphibiansGym - 101933A 看了眼榜没几个人做.就没看. 最后发现就是一个DP(但是我觉得复杂度有点迷) 题意: ...

  5. Nordic Collegiate Programming Contest (NCPC) 2016

    A Artwork B Bless You Autocorrect! C Card Hand Sorting D Daydreaming Stockbroker 贪心,低买高卖,不要爆int. #in ...

  6. (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...

  7. Nordic Collegiate Programming Contest 2017 题解

    前几天打了一场外国人的比赛,感觉那边的题目质量还是很好的,区分度很鲜明,题目没有国内的难,坑点比较少,比较注重思维,基础算法. B题: Best Relay Team Picture by Ferna ...

  8. 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    A Drawing Borders 很多构造方法,下图可能是最简单的了 代码: #include<bits/stdc++.h> using namespace std; const int ...

  9. Nordic Collegiate Programming Contest 2016

    A Artwork 输入: n,m表示原图为n*m个白色方格,输入x1,y1,x2,y2表示将x1,y1,x2,y2涂为黑色. 输出: 对于每个x1,y1,x2,y2输入当前图案白色联通块的数目. 思 ...

最新文章

  1. 雷蛇灯光配置文件_雷蛇猎魂光蛛竞技版机械键盘评测
  2. 解决Out of memory error (version 1.2-rc4 ‘Carnac‘ (298900 ... by android-jack-team@google.com)).
  3. android baseactivity,Android应用开发Android通过BaseActivity获取到当前启动的Activity名称...
  4. ariel字体_播客第58集:软件开发人员和freeCodeCamp超级巨星Ariel Leslie
  5. php layui 框架,Thinkphp5+Layui高颜值内容管理框架
  6. 图像处理 --- 二、数字图像处理基础
  7. phpstrom 本地编辑玩文件 自动临时映射到远程服务器
  8. 开始创建你的第一个 Flutter 应用
  9. 如果看了这篇文章你还不懂傅里叶变换,那就过来掐死我吧(下)
  10. 大数据系列2-liunx基础-1操作系统介绍
  11. 易语言学习笔记(一)
  12. L1-049 天梯赛座位分配(模拟)
  13. [Python从零到壹] 十八.可视化分析之Basemap地图包入门详解
  14. Metasploit入门使用手册
  15. 阿里云服务器持久内存型re6p实例采用Intel傲腾持久内存
  16. Es6常见面试题必看!
  17. 举着一片片小小柔柔的叶子
  18. 教程 | 虚拟机VMware Workstation Pro安装教程
  19. 文字识别(输入为自然场景中的图像)
  20. 复杂指令集与精简指令集的原子操作

热门文章

  1. apt-get 更新指定软件_GrandPerspective for mac(磁盘管理软件)
  2. http referer 验证防御方法_渗透测试 跨站攻击防御与安全检测手法剖析
  3. c++STL的反向迭代器
  4. 二叉树层序遍历(广度优先搜索)基础概念与经典题目(Leetcode题解-Python语言)
  5. [RabbitMQ]RabbitMQ概念_四大核心概念
  6. [C++STL]常用算术生成算法
  7. [蓝桥杯]字符串对比-模拟
  8. GCD and LCM Aizu - 0005(辗转相除)+GCD LCM Inverse POJ - 2429(java或【Miller Rabin素数測试】+【Pollar Rho整数分解】)
  9. 合并k个有序链表 python_leetcode第23题-合并K个有序链表
  10. 用函数求C15的值C语言,南开19春学期(1503、1509、1603、1609、1703)《C语言程序设计》在线作业-1辅导资料.docx...