九度oj 1031 xxx定律 2009年浙江大学计算机及软件工程研究生机试真题
题目1031:xxx定律
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:5153
解决:3298
- 题目描述:
-
对于一个数n,如果是偶数,就把n砍掉一半;如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数变为1为止。
请计算需要经过几步才能将n变到1,具体可见样例。
- 输入:
-
测试包含多个用例,每个用例包含一个整数n,当n为0 时表示输入结束。(1<=n<=10000)
- 输出:
-
对于每组测试用例请输出一个数,表示需要经过的步数,每组输出占一行。
- 样例输入:
-
3
1
0
- 样例输出:
-
5
0
#include <cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
struct point{
int dis,cost;
};
point p[];
int map[][][];
#define inf 999999999
int main(){
//freopen("D://INPUT.txt","r",stdin);
int n,m;
while(cin>>n>>m&&n&&m){
int i=,j;
for(i=;i<=n;i++){
for(j=;j<=n;j++){
map[i][j][]=inf;
map[i][j][]=inf;
}
}
i=;
for(;i<m;i++){
int a,b;
cin>>a>>b;
cin>>map[b][a][]>>map[b][a][];
map[a][b][]=map[b][a][];
map[a][b][]=map[b][a][];
}
int s,e;
cin>>s>>e;
//cout<<s<<e<<endl;
p[s].cost=;
p[s].dis=;
i=;
for(;i<=n;i++){
if(i==s)
continue;
p[i].dis=map[s][i][];
p[i].cost=map[s][i][];
}
i=;
for(;i<n;i++){
int j,min=inf,k;
for(j=;j<=n;j++){
if(p[j].dis&&p[j].dis<min){
min=p[j].dis;
k=j;
}
}
if(k==e){
break;
}
for(j=;j<=n;j++){
if(p[j].dis>p[k].dis+map[k][j][]){
p[j].dis=p[k].dis+map[k][j][];
p[j].cost=p[k].cost+map[k][j][];
}
else{
if(p[j].dis==p[k].dis+map[k][j][]){
p[j].cost=p[k].cost+map[k][j][]>p[j].cost?p[j].cost:p[k].cost+map[k][j][];
}
}
}
p[k].dis=;
}
cout<<p[e].dis<<' '<<p[e].cost<<endl;
}
return ;
}
/**************************************************************
Problem: 1008
User: Deribs4
Language: C++
Result: Accepted
Time:20 ms
Memory:9416 kb
****************************************************************/
九度oj 1031 xxx定律 2009年浙江大学计算机及软件工程研究生机试真题的更多相关文章
- 九度oj 1034 寻找大富翁 2009年浙江大学计算机及软件工程研究生机试真题
题目1034:寻找大富翁 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5323 解决:2123 题目描述: 浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁. 输入: ...
- 九度OJ 1019 简单计算器 -- 2006年浙江大学计算机及软件工程研究生机试真题
题目地址:http://ac.jobdu.com/problem.php?pid=1019 题目描述: 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. 输入: ...
- 九度oj 1006 ZOJ问题 2010年浙江大学计算机及软件工程研究生机试真题
题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:16244 解决:2742 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC.是 ...
- 九度oj 1003 A+B 2010年浙江大学计算机及软件工程研究生机试真题
题目1003:A+B 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:12812 解决:5345 题目描述: 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号",&qu ...
- 九度oj 1032 ZOJ 2009年浙江大学计算机及软件工程研究生机试真题
题目1032:ZOJ 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4102 解决:2277 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当 ...
- 九度oj 1004 Median 2011年浙江大学计算机及软件工程研究生机试真题
题目1004:Median 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:14162 解决:3887 题目描述: Given an increasing sequence S of N i ...
- 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题
题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...
- 九度oj 1468 Sharing 2012年浙江大学计算机及软件工程研究生机试真题
题目1468:Sharing 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2687 解决:550 题目描述: To store English words, one method is ...
- 九度oj 1464 Hello World for U 2012年浙江大学计算机及软件工程研究生机试真题
题目1464:Hello World for U 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:3872 解决:1082 题目描述: Given any string of N (> ...
随机推荐
- HBase介绍(4)---常用shell命令
进入hbase shell console$HBASE_HOME/bin/hbase shell如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成功之 ...
- 初学python - 脚本文件
解析: 第一行 #!/usr/bin/env python - py脚本运行环境[用python解释器解释脚本文件-对应python安装路径] 第二行 #-*-coding:utf-8-*- - ...
- ubantu18.04 配置nginx与uwsgi
一.首先先安装nginx静态服务 先更新 sudo apt-get update 1.安装gcc g++的依赖库 sudo apt-get install build-essential && ...
- 洛谷P5205 【模板】多项式开根(FFT)
题面 传送门 题解 考虑分治 假设我们已经求出\(A'^2\equiv B\pmod{x^n}\),考虑如何计算出\(A^2\equiv B\pmod{x^{2n}}\) 首先肯定存在\(A^2\eq ...
- GitHub访问下载太慢解决办法
原因 为什么慢?github的CDN被某墙屏了. 解决方法 绕过dns解析,在本地直接绑定host,该方法也可加速其他因为CDN被屏蔽导致访问慢的网站. 实现 在本地host文件中添加映射,步骤如下: ...
- Intellij idea maven 引用无法搜索远程仓库的解决方案
打开项目的POM文件,ALT+Insert键 出来添加引用的窗口 说明无法搜索到远程仓库,需要怎么设置呢? 在intellij idea 中配置好maven后 是这样的 如果加载失败,则需要自定义远程 ...
- 04. prosition 的值都有哪些,其最本质的区别在哪里?
4.prosition 的值都有哪些,其最本质的区别在哪里? position:relative 相对定位 position:fixed 相对浏览器定位 position:absolute 绝对定位 ...
- php7 中?? 和 ?:的区别
$b = $a?? $c ;相当于$b= isset($a)?$a:$c; $b = $a?: $c ;则是 $b = !empty($a) ? $a:$c;
- [转] Centos 系统swap虚拟内存添加与删除配置
[From]https://blog.csdn.net/lengyue1084/article/details/51405640 [From]https://yuukis.cn/24/ SWAP是Li ...
- Mbps、Kbps、KBps的关系
1. 每秒钟传输的二进制位数的单位:bps.Kbps.Mbps Mbps是Million bits per second的缩写,它的意思是时间内传输数据的平均比特数. Mbps=Mbit/s即兆比特每 ...