DIV1 250pt

题意:将一个数表示成质因子相乘的形式,若乘式所含数字的个数为质数,则称A为underprime。比如12 = 2*2*3,则含3个数字,是underprime。求A, B之间underprime的个数。A, B <= 10^5。

解法:暴力枚举A,B之间所有数,求出其乘式所含数字的个数, 判断是不是质数。

tag:brute-force

 // BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "Underprimes.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <set>
#include <queue>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; inline int MyMod( int a , int b ) { return (a%b+b)%b;}
int temp[] = {,,,,,,,}; class Underprimes
{
public:
bool gao(int x)
{
int cnt = ;
for (int i = ; i*i <= x; ++ i) if (!(x % i)){
while (!(x % i)) x /= i, ++ cnt;
}
if (x != ) ++ cnt;
for (int i = ; i < ; ++ i) if (cnt == temp[i]) return ;
return ;
}
int howMany(int A, int B){
int ret = ;
for (int i = B; i >= A; -- i)
if (gao(i)) ++ ret;
return ret;
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, howMany(Arg0, Arg1)); }
void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, howMany(Arg0, Arg1)); }
void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, howMany(Arg0, Arg1)); }
void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, howMany(Arg0, Arg1)); } // END CUT HERE };
//by plum rain
// BEGIN CUT HERE
int main()
{
//freopen( "a.out" , "w" , stdout );
Underprimes ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

DIV1 550pt

题意:用1*5的瓷砖将房间铺成如下图形状,现在给一个矩形的区域,重新铺里面的瓷砖。买一个1*5的瓷砖,可以将其切割成几小块使用,但不能将几小块合并成一个1*5的使用。问要重新铺所给区域瓷砖,最少买多少块1*5的瓷砖。

解法:分两步,第一步求出,给定区域内,含有1*5,1*4,1*3,1*2,1*1各多少块。这一步只能暴力求,不同的写法上可能有编码复杂度的差异,我觉得我的还行,就是效率不太高。。

   第二步,求出各种块的数量之后,求最少买多少块瓷砖。贪心思想,方法是从大往小扫,如果有1*4的,每块都配一个1*1的只要有,如果有1*3的尽量配1*2,不行就配1*1。。。。就是从大往小扫,匹配能匹配到的最大的瓷砖。这样的匹配方法在SRM 598 DIV1的250pt里面有用到。

tag:brute-force, greedy

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "BedroomFloor.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <bitset>
#include <list>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; class BedroomFloor
{
public:
int64 num[]; int64 min(int64 a, int64 b)
{
return a > b ? b : a;
} int64 gao(int64 sam, int64 s, int64 e, int64 len)
{
int64 tim = e/ - s/ - ;
if (tim < ){
if (sam) num[len] += e - s + ;
else num[e-s+] += len;
return ;
} int64 ret = ;
if (len == ) ret = tim * ;
else{
num[len] += (tim + (sam^)) / * ;
ret = (tim + sam) / * len;
} int64 up = (s/ + ) * ;
if (!sam) num[up-s] += len;
else num[len] += up - s; sam ^= (tim + ) & ;
int64 dn = e / * - ;
if (!sam) num[e-dn] += len;
else num[len] += e - dn; return ret;
} long long numberOfSticks(int x1, int y1, int x2, int y2){
clr0 (num);
int64 ret = ;
for (int i = x1; i < x2;){
ret += gao(((i/) & ) == ((y1/) & ), y1, y2-, min( - (i%), x2-i));
i = i / * + ;
} //for (int i = 1; i < 6; ++ i)
//tst(i), out (num[i]);
//
ret += num[];
if (num[] && num[]){
int64 tmp = min(num[], num[]);
ret += tmp;
num[] -= tmp; num[] -= tmp;
}
ret += num[]; if (num[] && num[]){
int64 tmp = min(num[], num[]);
ret += tmp;
num[] -= tmp; num[] -= tmp;
}
if (num[] && num[]){
int64 tmp = min(num[]/, num[]);
ret += tmp;
num[] -= *tmp; num[] -= tmp;
}
ret += num[];
num[] -= num[] * ; if (num[] && num[] > ){
int64 tmp = min(num[]/, num[]);
ret += tmp;
num[] -= tmp*; num[] -= tmp;
}
if (num[] > ) ret += num[]& ? num[]/+ : num[]/;
else if (num[] == ) ret += , num[] -= ; if (num[] > ) ret += num[]% ? num[]/+ : num[]/;
return ret;
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); }
//void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_1();}
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const long long &Expected, const long long &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 5LL; verify_case(, Arg4, numberOfSticks(Arg0, Arg1, Arg2, Arg3)); }
void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 5LL; verify_case(, Arg4, numberOfSticks(Arg0, Arg1, Arg2, Arg3)); }
void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 12LL; verify_case(, Arg4, numberOfSticks(Arg0, Arg1, Arg2, Arg3)); }
void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 27LL; verify_case(, Arg4, numberOfSticks(Arg0, Arg1, Arg2, Arg3)); }
void test_case_4() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 200000000000LL; verify_case(, Arg4, numberOfSticks(Arg0, Arg1, Arg2, Arg3)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
BedroomFloor ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

SRM 442(1-250pt, 1-500pt)的更多相关文章

  1. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  2. SRM468 - SRM469(1-250pt, 500pt)

    SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...

  3. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  4. SRM593(1-250pt,500pt)

    SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...

  5. topcoder srm 553

    div1 250pt: 题意:... 解法:先假设空出来的位置是0,然后模拟一次看看是不是满足,如果不行的话,我们只需要关心最后栈顶的元素取值是不是受空白处的影响,于是还是模拟一下. // BEGIN ...

  6. topcoder srm 552

    div1 250pt: 题意:用RGB三种颜色的球摆N层的三角形,要求相邻的不同色,给出RGB的数量,问最多能摆几个 解法:三种颜色的数量要么是全一样,要么是两个一样,另外一个比他们多一个,于是可以分 ...

  7. topcoder srm 551

    div1 250pt 题意:一个长度最多50的字符串,每次操作可以交换相邻的两个字符,问,经过最多MaxSwaps次交换之后,最多能让多少个相同的字符连起来 解法:对于每种字符,枚举一个“集结点”,让 ...

  8. topcoder srm 550

    div1 250pt: 题意:有个机器人,从某一点出发,他只有碰到地形边缘或者碰到走过的点时才会改变运动方向,然后接着走,现在给出他的运动轨迹,判断他的运动是否合法,如果合法的话,那么整个地形的最小面 ...

  9. topcoder srm 610

    div1 250pt: 题意:100*100的01矩阵,找出来面积最大的“类似国际象棋棋盘”的子矩阵. 解法:枚举矩阵宽(水平方向)的起点和终点,然后利用尺取法来找到每个固定宽度下的最大矩阵,不断更新 ...

随机推荐

  1. Linux Shell脚本之自动修改IP

    作为一名Linux SA,日常运维中很多地方都会用到脚本,而服务器的ip一般采用静态ip或者MAC绑定,当然后者比较操作起来相对繁琐,而前者我们可以设置主机名.ip信息.网关等配置.修改成特定的主机名 ...

  2. js中使用prototype扩展对象方法

    //---------------------对象 //1. var HomeContrl = function(){ this.foo = 'bar'; //对象方法 this.intro = fu ...

  3. 服务端生成word并压缩打包下载

    所需工具 phpwrod 库 php_zip 扩展 下载phpword库,放到类加载路径. 安装php_zip扩展 下载地址 http://pecl.php.net/package/zip linux ...

  4. iBatis系列之三

    iBatis和Hibernate最大差别就是在于iBatis没有严格的和具体的表做关联:而是将结果集和DAO做关联. iBatis的SqlConfig.xml配置一个properties文件,其实可以 ...

  5. IP,TCP,UDP Checksum校验

    IP数据报的校验: IP数据报只需要对数据头进行校验,步骤如下: 将接收到的数据的checksum字段设置为0 把需要校验的字段的所有位划分为16位(2字节)的字 把所有16位的字相加,如果遇到进位, ...

  6. java中关于移位运算符的demo与总结

    首先,移位运算符有三种,其操作类型只支持:byte / short / char / int和long五种. << 左移运算符,表示将左边的操作数的二进制数据向左移动*位,移动后空缺位以0 ...

  7. 根据WSDL生成代理类方式(2)

    运行开发人员工具提示 输入命令行svcutil http://localhost:8080/Test/TestClassPort?wsdl

  8. python 遍历字典

    dict={"a":"apple","b":"banana","o":"orange&qu ...

  9. django HTTP请求(Request)和回应(Response)对象

    Django使用request和response对象在系统间传递状态.—(阿伦)当一个页面被请示时,Django创建一个包含请求元数据的 HttpRequest 对象. 然后Django调入合适的视图 ...

  10. bzoj 3597: [Scoi2014]方伯伯运椰子 0/1分数规划

    3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 144  Solved: 78[Submit][Status ...