SGU 108. Self-numbers 2 离线+位优化
来源:互联网 发布:航天税控发票软件 编辑:程序博客网 时间:2024/05/22 07:42
可以像筛选法那样标记 但是内存最多只能开1024的int数组 我用了位优化 用一个int 32 位标记32个数字 接下来就离线 排个序 算出第k大的哪个数
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[10000000/32];struct node{int x, y, id;}b[50010];int get(int x){int ans = x;while(x){ans += x%10;x /= 10;}return ans;}void dfs(int x){int tmp = x + get(x);if(tmp > 10000000 || a[tmp])return;a[tmp] = 1;dfs(tmp);}bool cmp1(node a, node b){return a.x < b.x;}bool cmp2(node a, node b){return a.id < b.id;}int main(){//for(int i = 1; i <= 10000; i++)//p[i] = get(i);int n, k;while(scanf("%d %d", &n, &k) != EOF){for(int i = 0; i < k; i++){scanf("%d", &b[i].x);b[i].id = i;}sort(b, b+k, cmp1);memset(a, 0, sizeof(a));int c = 0, j = 0;for(int i = 1; i <= n; i++){if(!(a[i/32]&(1<<(i%32)))){c++;while(j < k && b[j].x == c){b[j].y = i;j++;}}int x = get(i);if(x <= n)a[x/32] |= (1<<(x%32));}printf("%d\n", c);sort(b, b+k, cmp2);for(int i = 0; i < k; i++){if(i)printf(" ");printf("%d", b[i].y);}puts("");}return 0;}
0 0
- SGU 108. Self-numbers 2 离线+位优化
- 【SGU】108. Self-numbers 2
- [SGU]108. Self-numbers II
- sgu 108-self-numbers 2
- SGU 108 Self-numbers 2
- sgu 108 Self-numbers 2
- sgu 108 self-numbers 2
- sgu 108 Self-numbers 2
- SGU 108 Self-numbers 2(数论)
- SGU 159 - Self-Replicating Numbers
- SGU 108 Self-numbers II
- SGU 108 Self-numbers 2 (另一种滚动数组)
- 108. Self-numbers 2
- [SGU 108]Self-numbers II(筛法活用优化+滚动数组)
- 离线 + 位优化
- Self-numbers 2
- SGU108 Self-numbers 2
- Self Numbers
- Oracle VM VirtualBox安装centos 7
- head及body
- 理解 this.initialize.apply ( this, arguments )
- 关于 PostgreSQL 监控工具的学习
- HDU 5039 Hilarity
- SGU 108. Self-numbers 2 离线+位优化
- Android蓝牙编程经验总结——同时传输数据和音频
- 机房管理--如何应对学生关闭极域电子教室
- Android中RelativeLayout各个属性的含义
- 处理oracle逻辑备库不应用某一个特定dml语句
- java中使用mysql查询 条件中含有中文时查询不到结果解决方案
- jQuery的Ajax跨域请求
- 高校信息化建设发展方向——资源利用
- Java常用工具类集合