HDU 3784 继续xxx定律 & HDU 2578 Dating with girls(1)
HDU 3784 继续xxx定律
HDU 2578 Dating with girls(1)
做3748之前要先做xxx定律 对于一个数n,如果是偶数,就把n砍掉一半;如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数变为1为止。
当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数,5,8,4,2称为覆盖数。现在输入n个数字a[i],根据关键数与覆盖数的理论,我们只需要验证其中部分数就可以确定所有数满足xxx定律,输出输入的n个数中的关键数。如果其中有多个关键数的话按照其输入顺序的逆序输出。
所以只需把n个数都当做关键数,一一标记a[i]的覆盖数,最后在这数列中找到未被标记的,逆序输出。
15 ms
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- int a[],b[],i,n,x,y,c[]; //a为原数列,b为未被标记的数列,c为标记,记得c要开很大,因为要(x*3+1)/2可能很大
- while(~scanf("%d",&n)&&n)
- {
- memset(c,,sizeof(c)); //清零
- for(i=;i<=n;i++)
- scanf("%d",&a[i]);
- for(i=;i<=n;i++)
- {
- x=a[i];
- if(!c[x]) //未被标记,若已被标记那么x的覆盖数已全被标记
- while(x!=)
- {
- if(x%==)
- {
- x/=;
- c[x]=;
- }
- else
- {
- x=(*x+)/;
- c[x]=;
- }
- }
- }
- y=;
- for(i=;i<=n;i++)
- if(c[a[i]]==) //未被标记
- b[++y]=a[i];
- for(i=y;i>=;i--) //逆序输出
- printf("%d ",b[i]);
- printf("%d\n",b[]);
- }
- return ;
- }
第二题 2578
大意是:给出n个数,满足x属于n,y属于n,x+y=k的方案数。 PS;1+3和3+1算两种,2+2只算一种
刚开始想用母函数做.....后来发现k<2^31,数组开不了这么大T^T
后来是周XX说用二分= =,想想也是......
然后各种改,错了6次!!!! 406MS
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- int main()
- {
- int T,n,k,i,a[],l,r,sum,x,mid,y;
- scanf("%d",&T);
- while(T--)
- {
- sum=;
- y=;
- scanf("%d%d",&n,&k);
- for(i=;i<=n;i++)
- {
- scanf("%d",&a[i]);
- if(k%==&&a[i]==k/) //如果存在k/2这个数,则方法数+1
- y=;
- }
- a[]=-;
- sort(a+,a+n+); //排序
- for(i=;i<=n;i++)
- if(a[i]<(k+)/ && a[i]!=a[i-]) //先1,3;3,1只算一种,不要重复算 ①
- {
- x=k-a[i]; //找y
- l=;
- r=n+; //②
- mid=(l+r)/;
- while(r-l>) //③
- {
- mid=(l+r)/;
- if(a[mid]>x)
- r=mid;
- if(a[mid]<x)
- l=mid;
- if(a[mid]==x)
- break;
- }
- if(a[mid]==x)
- sum++;
- }
- sum=sum*+y; //sum*2+是否有x=y这种情况
- printf("%d\n",sum);
- }
- return ;
- }
做的时候有几个易错的地方: ①②③
还有一组很难过得数据:
3 4
1 2 3
两道这样的题做了那么久.......╭(╯^╰)╮
HDU 3784 继续xxx定律 & HDU 2578 Dating with girls(1)的更多相关文章
- hdu 2578 Dating with girls(1)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2578 Dating with girls(1) Description Everyone in the ...
- hdu 2578 Dating with girls(1) (hash)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 2578 Dating with girls(1) [补7-26]
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2578 Dating with girls(1) 满足条件x+y=k的x,y有几组
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2579 Dating with girls(2)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2579 Dating with girls(2) Description If you have sol ...
- HDU 3782 xxx定律
xxx定律 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 2579 Dating with girls(2) (bfs)
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Top ShooterHDU2863&&继续xxx定律HDU3784
继续xxx定律 HDU3784 先看这个题目:HDU3782 #include<iostream> #include<algorithm> #include<stdio. ...
- 每日一九度之 题目1033:继续xxx定律
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5502 解决:1351 题目描述: 当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数, ...
随机推荐
- weiphp插件开发注意
插件命名要规范,插件名文件名,控制器名,模型名要以大写开头.不然的话会有惊喜!╮(╯▽╰)╭
- js获取标签的三种方式
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- deepin 安装 idea
1.su root 2.sudo apt install idea 3.sudo vi /etc/hosts 最后一行添加 0.0.0.0 account.jetbrains.com 4.注册码 N7 ...
- 第八届河南省省赛 A.挑战密室
挑战密室 时间限制: ms | 内存限制: KB 难度: 描述 R组织的特工Dr. Kong 为了寻找丢失的超体元素,不幸陷入WTO密室.Dr. Kong必须尽快找到解锁密码逃离,否则几分钟之后,WT ...
- Linux学习之路2 Bash的基本操作
一.SHELL的介绍 shell分为两种:CLI(command Line Interface)和GUI(Graphical User Interface) 操作系统中的shell: GUI:GNOM ...
- 题解报告:hdu 5695 Gym Class(拓扑排序)
题目链接:acm.hdu.edu.cn/showproblem.php?pid=5695 Problem Description 众所周知,度度熊喜欢各类体育活动.今天,它终于当上了梦寐以求的体育课老 ...
- ACM_下一个排列
The Next Permutation Time Limit: 2000/1000ms (Java/Others) Problem Description: For this problem, yo ...
- document.write()、onclick="alert(xxx)、innerHTML、image.src.match("xxx")、id2.style.color="blue";、isNaN(id2)、document.write("糟糕!文档消失了。")、alert(id2.outerHTML)、id2.className="id06";、onclick="return registe"
<html> <head> <meta charset="utf-8"> <title>javascript</title&g ...
- [转]微信开发.Net 接入示例
本文转自:http://my.oschina.net/lcak/blog/219618 微信公众平台接口开发官方仅提供了 PHP 接入示例代码, 网上找到的.Net代码多半需要积分下载, 所以自己写了 ...
- Mysql慢SQL与索引案例
写在最前 关于慢sql的开启与配置查看之前我整理的文章: http://www.cnblogs.com/hanxiaobei/p/5515624.html 前提准备: tomcat7.x mysql- ...