跳过正文
  1. Posts/

codeforces #332 div 2 D. Spongebob and Squares

·2 分钟

http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的时候gg了。。其实稍微在纸上推一下。就会得到对于n,m的矩形,一共会有-nnn+3nnm+n+3n*m的方格。数量级是n3。 我们可以实际跑一遍。发现对于x1E18的数量级,n不会超过1442550,1E6,可以搞。

需要注意的是,一个是会爆int,所以记得用long long

另一个是如果两个数相等,记得只输入一组,并且方案数-1

我是用set +pair存的答案。。反向遍历set的时候要用reserve_iterator…

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2015年12月23日 星期三 15时54分37秒
 4File Name :code/cf/#332/D.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < LL ,LL >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33LL x;
34LL cur;
35const LL MAXN = 1442550;
36set<pi>se;
37LL cal( LL n,LL m)
38{
39    LL res = -n*n*n+3*n*n*m+3*n*m+n;
40    return res;
41}
42int square = -1;
43int main()
44{
45	#ifndef  ONLINE_JUDGE
46	freopen("code/in.txt","r",stdin);
47  #endif
48//	for ( LL i = 1 ; ; i++)
49//	{
50//	    cur = cal(i,i);
51//	  //  cout<<"i:"<<i<<" cur:"<<cur<<endl;
52//	    if (cur>1E18)
53//	    {
54//		cout<<i<<endl;
55//		break;
56//	    }
57//
58//	}
59	cin>>x;
60	x = x*6;
61	for ( LL i = 1 ; cal(i,i)<=x ; i++)
62	{
63	    LL tmp = (x-i+i*i*i)%(3*i*i+3*i);
64	  //  cout<<"i:"<<i<<" tmp:"<<tmp<<endl;
65	    if (tmp==0)
66	    {
67		se.insert(make_pair(i,(x-i+i*i*i)/(3*i*i+3*i)));
68		if (i==(x-i+i*i*i)/(3*i*i+3*i)) square = 1;
69
70	    }
71	}
72	if (square==1)
73	cout<<se.size()*2-1<<endl;
74	else cout<<se.size()*2<<endl;
75	set<pi>::iterator it;
76	for (it = se.begin(); it!=se.end() ;it++)
77	{
78
79	    cout<<(*it).fst<<" "<<(*it).sec<<endl;
80	}
81	set<pi>::reverse_iterator it2;   //反向遍历要用反向迭代器。。。右忘记了。。。。
82	for ( it2 =se.rbegin() ;it2 !=se.rend() ; it2 ++)
83	{
84	    if (square==1)
85	    {
86		square = 2;
87		continue;
88	    }
89
90
91	    cout<<(*it2).sec<<" "<<(*it2).fst<<endl;
92	}
93
94
95  #ifndef ONLINE_JUDGE
96  fclose(stdin);
97  #endif
98    return 0;
99}

相关文章

codeforces #333 div 2B. Approximating a Constant Range

·2 分钟
http://codeforces.com/contest/602/problem/B 题意:给定n个数,问最大连续区间长度,满足这段区间内最大值和最小值的差的绝对值小于等于1. 思路:尺取+set。尺取法,由于要时刻得到一段区间的最大值和最小值,而且可能有重复元素,所以用multiset.

codeforces #333 div 2 D. Lipshitz Sequence

·3 分钟
http://codeforces.com/contest/602/problem/D 题意:见题目描述。 思路:我们很容易发现,l[h]函数其实就是在求区间斜率的最大值。哦不对,是斜率的绝对值的最大值。而且一个显而易见的结论是,斜率最大值一定是由相邻的点得到。画图可以很容易看出。

poj 3687 Labeling Balls

http://poj.org/problem?id=3687 题意:给定几个标签球的重量大小关系,求每个球是第几重的(即每个球在所有球的重量中由小到大排名是多少)。 (输出是每个球第几重,而不是几号球比几号球重!)。一开始理解错了QAQ 思路:反向拓扑+优先队列。因为正向不好用。。。所以我们连边的时候由重的指向轻的。。这样最先出队的就是最重的。。和上道题差不多?

hdoj4391 Paint The Wall

·2 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=4391 题意:有 n 个点,每个点有一种颜色(可能相同),两种操作:1、将区间 [a,b] 染成颜色 c ; 2、询问区间 [a,b] 中颜色为 c 的点有多少个。 思路:因为颜色种类很多。。。没办法通过建很多棵线段树解决。我们用分块的办法。。。

codeforces 522 A. Vanya and Table

http://codeforces.com/problemset/problem/552/A 题意:一个100*100的网格。然后给n个矩形。每个格子中填上包含这个格子的矩形的个数。最后问所有格子的和。 思路:树状数组搞得…然而..直接求所有矩形面积的和就可以啊喂。。o(n)。。。111qqz你个炒鸡大菜鸡。