2012年8月9日

hdu4350

摘要: 刚开始我被这道题吓到了,心想这要移动这么多次,这不是要超时吗,后来又感觉是约瑟夫问题,唉,想起约瑟夫问题就想起了那个难记的公式,唉,直接放弃了,后来才发现,这道题原来是这么的easy,水题思路:认真观察即可发现,这道题是有规律的,不会让你去循环这么多次,拿个简单的的例子试下,你会发现,当移动r(题目中给的数)次时,数组又回到了原来的样子,所以可直接循环n%r次、 1 #include <iostream> 2 3 using namespace std; 4 int a[55]; 5 int tmp[55]; 6 int main() 7 { 8 int Case; 9 ci... 阅读全文

posted @ 2012-08-09 18:19 矮人狙击手! 阅读(256) 评论(0) 推荐(0) 编辑

hdu4351

摘要: 这道题我感觉应该用线段树来做,写了之后还是超时,别的优化方法想不到了,欢迎各位指教(补充一点优化的方法,第一求root digit的时候可以直接对9取余,如果是9的倍数,那么直接就是9,第二在build的时候在最后面加这样一句话:if(b[i].sum>9) b[i].sum-=9;) 1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 int a[100005]; 6 int res[100005*4]; 7 struct 阅读全文

posted @ 2012-08-09 17:41 矮人狙击手! 阅读(309) 评论(0) 推荐(0) 编辑

导航