↓ Skip to main content
  1. Posts/

poj 2100 Graveyard Design (two pointers ,尺取法)

·314 words·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

不多说,直接代码。

代码实现
 1/*************************************************************************
 2	> File Name: code/poj/2100.cpp
 3	> Author: 111qqz
 4	> Email: rkz2013@126.com
 5	> Created Time: 2015年09月25日 星期五 00时42分49秒
 6 ************************************************************************/
 7
 8#include<iostream>
 9#include<iomanip>
10#include<cstdio>
11#include<algorithm>
12#include<cmath>
13#include<cstring>
14#include<string>
15#include<map>
16#include<set>
17#include<queue>
18#include<vector>
19#include<stack>
20#include<cctype>
21#define y1 hust111qqz
22#define yn hez111qqz
23#define j1 cute111qqz
24#define ms(a,x) memset(a,x,sizeof(a))
25#define lr dying111qqz
26using namespace std;
27#define For(i, n) for (int i=0;i<int(n);++i)
28typedef long long LL;
29typedef double DB;
30const int inf = 0x3f3f3f3f;
31LL n;
32LL maxn;
33vector<LL>ans;
34
35
36void solve()
37{
38    LL head = 1,tail = 1;
39    LL sum = 0 ;
40
41    while (tail<=maxn)
42    {
43	sum = sum + tail*tail;
44
45	if (sum>=n)
46	{
47	    while (sum>n)//主要是while,因为可能要减掉多个才能小于n
48	    {
49		sum -= head*head;
50		head++;
51	    }
52	    if (sum==n)
53	    {//因为要先输出答案个数...所以必须存起来延迟输出...
54		ans.push_back(head);
55		ans.push_back(tail);
56	    }
57	}
58	tail++;
59    }
60    LL sz = ans.size();
61    printf("%lld\n",sz/2);
62    for (LL i = 0 ; i<ans.size() ; i = i +2)
63    {
64	printf("%lld",ans[i+1]-ans[i]+1);
65	for ( LL j = ans[i] ; j <=ans[i+1] ; j++) printf(" %lld",j);
66	printf("\n");
67    }
68
69}
70int main()
71{
72  #ifndef  ONLINE_JUDGE
73   freopen("in.txt","r",stdin);
74  #endif
75    scanf("%lld",&n);
76    maxn = ceil(sqrt(n));
77    solve();
78
79 #ifndef ONLINE_JUDGE
80  fclose(stdin);
81  #endif
82	return 0;
83}

Related

poj 3320 Jessica's Reading Problem (尺取法)

·1180 words·3 mins
Jessica’s Reading Problem Time Limit Memory Limit Total Submissions Accepted 1000MS 65536K 8787 2824 Description Jessica’s a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a very thick text book. The author of that text book, like other authors, is extremely fussy about the ideas, thus some ideas are covered more than once. Jessica think if she managed to read each idea at least once, she can pass the exam. She decides to read only one contiguous part of the book which contains all ideas covered by the entire book. And of course, the sub-book should be as thin as possible.

poj 2159 Ancient Cipher(水)

·348 words·1 min
由于顺序是可以改变的. 所以考虑是否可以映射.只要存在字母对应出现的次数都相同.那么就可以通过映射得到. 具体是开一个数组记录每个字母出现的次数… 然后sort

hdu 1849Rabbit and Grass(一维nim游戏,sg函数)

·1290 words·3 mins
Rabbit and Grass # **Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3058 Accepted Submission(s): 2261 ** Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去逛公园,不去和AC男约会,两个人竟然猫在寝食下棋…… 说是下棋,其实只是一个简单的小游戏而已,游戏的规则是这样的: 1、棋盘包含1*n个方格,方格从左到右分别编号为0,1,2,…,n-1; 2、m个棋子放在棋盘的方格上,方格可以为空,也可以放多于一个的棋子; 3、双方轮流走棋; 4、每一步可以选择任意一个棋子向左移动到任意的位置(可以多个棋子位于同一个方格),当然,任何棋子不能超出棋盘边界; 5、如果所有的棋子都位于最左边(即编号为0的位置),则游戏结束,并且规定最后走棋的一方为胜者。