MCPC 2011Hdu4207-4214(未完全)题解

第一题:Grade School Multiplication

http://acm.hdu.edu.cn/showproblem.php?pid=4207

题目大意:给你两个数,要求按照题目所讲的规律一步步得出结果。

如:给你两个数432  和 5678,你就要按照下面的规律输出

432

5678

-------

3456

3024

2592

2160

-------

2452896

模拟。

因为数据范围不是很大,所以直接用long long型计算每一位然后输出结果就行。

注意:特别要注意0的情况,因为没有考虑这种情况导致了多次wa。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
template <class T> void checkmin(T &t,T x) {if(x < t) t = x;}
template <class T> void checkmax(T &t,T x) {if(x > t) t = x;}
template <class T> void _checkmin(T &t,T x) {if(t==-1) t = x; if(x < t) t = x;}
template <class T> void _checkmax(T &t,T x) {if(t==-1) t = x; if(x > t) t = x;}
typedef pair <int,int> PII;
typedef pair <double,double> PDD;
typedef long long ll;
#define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end ; it ++)
ll a , b;
int cas = 1;
int wei(ll a) {int ans = 0;while(a) {a /= 10;ans ++;}checkmax(ans , 1);return ans;
}
int oowei(ll a) {int ans = 0;while(a) {if(a % 10 != 0) ans ++;a /= 10;}checkmax(ans , 1);return ans;
}
int main() {while(cin >> a >> b) {if(a + b == 0) break;printf("Problem %d\n",cas++);ll c = a * b;int Wa = wei(a) , Wb = wei(b) , Wc = wei(c);if(c == 0) {int dd = max(Wa , Wb);if(a != 0) cout << a << endl;else for(int i=1;i<dd;i++) putchar(' ');cout << a << endl;if(b != 0) cout << b << endl;else for(int i=1;i<dd;i++) putchar(' ');cout << b << endl;for(int i=0;i<dd;i++) putchar('-');puts("");for(int i=1;i<dd;i++) putchar(' ');cout << c << endl;continue;}int oWb = oowei(b);for(int i=0;i<Wc-Wa;i++) putchar(' ');cout << a << endl;for(int i=0;i<Wc-Wb;i++) putchar(' ');cout << b << endl;for(int i=0;i<Wc;i++) putchar('-');puts("");int cc = 0;ll ad = 0;while(b) {ll d = b%10;b /= 10;if(d == 0) { ad +=1; cc++; continue; }d *= a;ll Wd = wei(d);for(int i=0;i<Wc-Wd-cc;i++) putchar(' ');cout << d ;while(ad > 0) putchar('0') , ad -= 1;cout << endl;cc ++;}if(oWb > 1) {for(int i=0;i<Wc;i++) putchar('-');puts("");cout << c << endl;}}return 0;
}

第二题:Laser Tag

http://acm.hdu.edu.cn/showproblem.php?pid=4208

题目大意:有n面镜子( 1 ≤ n ≤ 7),现在我站在(0,0)点发射激光,激光照到镜子上会按照物理规律反射,最后有可能射到我自己;求沿x轴正方向0->359度所有能伤到自己的发射角度。

计算几何。

(题解:暂缺)

第三题:Pizza Pricing

http://acm.hdu.edu.cn/showproblem.php?pid=4209

题目大意:简单题。找价值最高的pizza,输出他的直径。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
template <class T> void checkmin(T &t,T x) {if(x < t) t = x;}
template <class T> void checkmax(T &t,T x) {if(x > t) t = x;}
template <class T> void _checkmin(T &t,T x) {if(t==-1) t = x; if(x < t) t = x;}
template <class T> void _checkmax(T &t,T x) {if(t==-1) t = x; if(x > t) t = x;}
typedef pair <int,int> PII;
typedef pair <double,double> PDD;
typedef long long ll;
#define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end ; it ++)
int n , a , b , ans , cas = 1;
double tmp;
int main() {while(~scanf("%d",&n) && n) {tmp = -1.0;for(int i=0;i<n;i++) {scanf("%d%d",&a,&b);double tp = ((double)(a*a)) / ((double)b);if(tp > tmp) {ans = a; tmp = tp;}}printf("Menu %d: %d\n",cas++,ans);}return 0;
}

第四题:Su-domino-ku

http://acm.hdu.edu.cn/showproblem.php?pid=4210

题目大意:数独题目的变形。要求拼出符合如下规律的数独:
Each row must contain each of the digits 1 through 9.
Each column must contain each of the digits 1 through 9.
Each of the indicated three-by-three squares must contain each of the digits 1 through 9.
For a su-domino-ku, nine arbitrary cells are initialized with the numbers 1 to 9. This leaves 72 remaining cells. Those must be filled by making use of the following set of 36 domino tiles. The tile set includes one domino for each possible pair of unique numbers from 1 to 9 (e.g., 1+2, 1+3, 1+4, 1+5, 1+6, 1+7, 1+8, 1+9, 2+3, 2+4, 2+5, ...). Note well that there are not separate 1+2 and 2+1 tiles in the set; the single such domino can be rotated to provide either orientation. Also, note that dominos may cross the boundary of the three-by-three squares (as does the 2+9 domino in our coming example).

DLX解决精确覆盖问题。

代码:

第五题:Refrigerator Magnets

http://acm.hdu.edu.cn/showproblem.php?pid=4211

题目大意:输入多串数,如果某个串中没有那个字母出现超过一次,则输出。

简单题。直接check一下就行。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
template <class T> void checkmin(T &t,T x) {if(x < t) t = x;}
template <class T> void checkmax(T &t,T x) {if(x > t) t = x;}
template <class T> void _checkmin(T &t,T x) {if(t==-1) t = x; if(x < t) t = x;}
template <class T> void _checkmax(T &t,T x) {if(t==-1) t = x; if(x > t) t = x;}
typedef pair <int,int> PII;
typedef pair <double,double> PDD;
typedef long long ll;
#define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end ; it ++)
int main() {char ch[100100];bool vis[26];while(gets(ch)) {if(strcmp(ch,"END") == 0) break;int ok = 1;memset(vis,0,sizeof(vis));for(int i=0;ch[i];i++) {if(ch[i] == ' ') continue;int t = ch[i] - 'A';if(vis[t]) { ok=0;break; }vis[t] = 1;}if(ok) puts(ch);}return 0;
}

第六题:Shut the Box

http://acm.hdu.edu.cn/showproblem.php?pid=4212

题目大意:给出一些数的集合S,然后给出一个个数Ai,对于Ai,必须取出S中的一些数使他们的和是Ai。问最多能坚持到第几个数。

题解:(暂缺)。

第七题:Sokoban

http://acm.hdu.edu.cn/showproblem.php?pid=4213

题目大意:

题解:(暂缺)

第八题:Crash and Go(relians)

http://acm.hdu.edu.cn/showproblem.php?pid=4214

题目大意:平面上有一些圆,对于彼此n个相交的圆,对他们的合并操作是:原来的圆消失,新圆的圆心坐标是n个圆坐标的平均值,新圆的半径是n个圆半径的和。问经过若干次合并操作后平面上一共还剩下几个圆。

模拟。

(暂wa)

转载于:https://www.cnblogs.com/aiiYuu/archive/2013/03/28/2985863.html

MCPC 2011Hdu4207-4214(未完全)题解相关推荐

  1. 字节面试现场,问我如何高效设计一个LRU

    前言 大家好,我是bigsai,好久不见,甚是想念! 最近有个小伙伴跟我诉苦,说他没面到LRU,他说他很久前知道有被问过LRU的但是心想自己应该不会遇到,所以暂时就没准备. 奈何不巧,这还就真的考到了 ...

  2. 剑指offer(60-67题)详解

    文章目录 60 把二叉树打印成多行 61 序列化二叉树 62 二叉搜索树第K个节点 63 数据流中的中位数 64 滑动窗口的最大值 65 矩阵中的路径 66 机器人的运动范围 67 剪绳子 欢迎关注个 ...

  3. 剑指offer(34-40题)详解

    文章目录 34 第一个只出现一次的字符 35 数组中的逆序数 36 两个链表的第一个公共节点 37 数字在排序数组中出现的次数 38 二叉树的深度 39 平衡二叉树 40 数组中只出现一次的数字 欢迎 ...

  4. 剑指offer(26-33题)详解

    文章目录 26 二叉搜索树与双向链表 27 字符串的排列 28 数字中出现次数超过一半的数字(待优化)★ 29 最小的K个数 30 连续子数组最大和 31 整数中1出现的次数 32 把数组排成最小的数 ...

  5. 剑指offer(11-25题)详解

    文章目录 11 二进制种1的个数★ 12 数值的正数次方 13 调整数组顺序使奇数位于偶数前面 14 链表中倒数第K个节点 15 反转链表 16 合并两个排序的链表 17 树的子结构 18 二叉树的镜 ...

  6. 剑指offer(1-10题)详解

    文章目录 01二维数组的查找 02替换空格 03从尾到头打印链表 04重建二叉树★ 05 用两个栈实现队列 06旋转数组的最小数字 07 斐波那契数列 08 跳台阶 09 变态跳台阶★ 10 矩阵覆盖 ...

  7. POJ1042 John钓鱼 C语言代码

    POJ1042 题目不再描述了,上面是网址超链接. 个人遭遇···: 简而言之,读了N遍题.脑子里想了半天(time>=1.5h),出现了无数想法,考虑了很多情况,仍然找不到切入点.于是,我就是 ...

  8. LeetCode Top100特训

    更新中-- 两数相加 盛水最多的容器 电话号码的字母组合 删除链表的倒数第 N 个结点 字母异位词分组 寻找两个正序数组的中位数 合并区间 不同路径(与最小路径和类似) 正则表达式匹配 颜色分类 单词 ...

  9. 代码随想录算法训练营第二天 | LeetCode 977.有序数组的平方、209.长度最小的子数组、59.螺旋矩阵II

    目录 一.今日心得感悟 1.数组从小到大排序 ①冒泡法--时间复杂度:O(nlogn) ②使用排序函数qsort--时间复杂度:O(nlogn) ③两端->中间(双指针法) --时间复杂度:O( ...

  10. 力扣每日一题——三角形的最大周长

    题目链接 class Solution {public:int largestPerimeter(vector<int>& A) {sort(A.begin(),A.end()); ...

最新文章

  1. 200秒=超算1万年,谷歌实现“量子霸权”论文上架随即被撤回,引发全球热议...
  2. Flask abort
  3. 贝叶斯学习举例--学习分类文本
  4. 【深度学习】深度学习中的单元测试
  5. c#子线程中打开系统文件操作对话框
  6. 138 张图带你 MySQL 入门!
  7. html5自由者,排球自由人可以一直不下场吗?就是可不可以一直在后排轮换?
  8. java接口回调学习
  9. 当个性化推荐遇上知识图谱.pdf(附下载链接)
  10. 你有什么办法可以让摄影的模特又高又美?
  11. 2012总结--目录
  12. 用glew,glfw实现opengl-学习笔记3着色器
  13. excel如何绘制箱线图 (初级版)
  14. 基于python的单词查询
  15. Blackhat2017:如何利用PostScript语言入侵打印机
  16. PageBarHelper(数字页码条帮助类)
  17. PC版微信加密图片解密思路与代码实现_Python
  18. MES系统是如何解决工厂上的难题的?
  19. 163vip.com登陆TOM邮箱,定位商务人士的专属邮箱!
  20. html5的video在IOS端默认全屏和黑屏问题

热门文章

  1. LINUX使用C执行系统命令ping,读取执行结果的崩溃日志
  2. IT行业上盘与碟的区别
  3. php支付自定义金额,自定义付款/支付/收费
  4. 同台加载_跨年官宣 | “爷青回”我只服湖南卫视跨年 李易峰陈伟霆马天宇“古剑三侠”同台...
  5. 什么是sql注入_什么是Python SQL注入?又如何使用Python防止SQL注入攻击呢?
  6. 关键路径例题图解_图解!九大常见数据结构被24张图给安排的明明白白
  7. FastDFS入门一篇就够 1
  8. nexus搭建maven私服及私服jar包上传和下载
  9. OC语言——————表视图
  10. 老李分享:性能测试过程