1007 正整数分组 1010 只包含因子2 3 5的数 1014 X^2 Mod P 1024 矩阵中不重复的元素 1031 骨牌覆盖
1007 正整数分组
第1行:一个数N,N为正整数的数量。
第2 - N+1行,N个正整数。
(N <= 100, 所有正整数的和 <= 10000)
输出这个最小差
5
1
2
3
4
5
1
这题不就是小李打怪兽吗,不知道谁模仿谁,呵呵,刚还是我编的题里的,dp,证明一下(要证明什么自己考虑)。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std; int n,sum;
bool boo[]; int main()
{
scanf("%d",&n);
boo[]=true,sum=;
int x;
for (int i=;i<=n;i++)
{
scanf("%d",&x);
for (int j=;j>=x;j--)
if (boo[j-x]) boo[j]=true;
sum+=x;
}
int i=sum/,j=sum-i;
while (!boo[i]||!boo[j]) i--,j++;
printf("%d\n",j-i);
}
1010 只包含因子2 3 5的数
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行1个数N(1 <= N <= 10^18)
共T行,每行1个数,输出>= n的最小的只包含因子2 3 5的数。
5
1
8
13
35
77
2
8
15
36
80
枚举处理出在范围内的所有满足条件的数+排序,然后二分找答案就可以了。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std; typedef long long LL;
const LL INF=1e18+; int n,cnt=;
LL a[]; void init()
{
for (LL i=;i<=INF;i*=)
for (LL j=;j*i<=INF;j*=)
for (LL k=;k*i*j<=INF;k*=)
a[++cnt]=i*j*k;
sort(a+,a+cnt+);
}
int main()
{
init();
scanf("%d",&n);
LL x;
for (int i=;i<=n;i++)
{
scanf("%lld",&x);
printf("%lld\n",*lower_bound(a+,a+cnt+,x));
}
}
1014 X^2 Mod P
两个数P A,中间用空格隔开。(1 <= A < P <= 1000000, P为质数)
输出符合条件的X,且0 <= X <= P,如果有多个,按照升序排列,中间用空格隔开。
如果没有符合条件的X,输出:No Solution
13 3
4 9
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std; int top=,p,a;
int ans[]={}; int main()
{
scanf("%d%d",&p,&a);
for (int i=;i<=p;i++)
{
long long x;
x=(long long)i*i;
if (x%p==a) ans[++top]=i;
}
if (top==) printf("No Solution\n");
else
{
for (int i=;i<top;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[top]);
}
}
1024 矩阵中不重复的元素
输入数据包括4个数:m,n,a,b。中间用空格分隔。m,n为矩阵的长和宽(2 <= m,n <= 100)。a,b为矩阵的第1个元素,a^b(2 <= a , b <= 100)。
输出不重复元素的数量。
4 3 2 2
11
一个hash的事情。
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
#include<map>
using namespace std; typedef long long LL;
const LL mod=; int m,n,a,b,ans;
map<int,bool>p; int main()
{
scanf("%d%d%d%d",&m,&n,&a,&b);
ans=m*n;
for (int i=;i<=n;i++)
{
LL x=,jed=(a+i-);
for (int j=;j<b;j++)
x=x*jed%mod;
for (int j=;j<=m;j++)
{
x=x*jed%mod;
if (p[x]) ans--;
else p[x]=true;
}
}
printf("%d\n",ans);
}
1031 骨牌覆盖

输入N(N <= 1000)
输出数量 Mod 10^9 + 7
3
3
比铺砖块要水吧,转移的东西都少,一般的状态压缩。
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std; const int mod=1e9+; int n,m,cnt=;
int f[][]={};
struct Node
{
int x,y;
}next[]; void dfs(int num,int sta,int old)
{
if (num>m) return;
if (num==m)
{
next[++cnt].x=old;
next[cnt].y=sta;
return;
}
dfs(num+,(sta<<)+,old<<);
dfs(num+,sta<<,old<<);
dfs(num+,sta<<,(old<<)+);
}
int main()
{
scanf("%d",&n);
m=;
dfs(,,);
f[][]=;
for (int i=;i<=n;i++)
for (int j=;j<=cnt;j++)
{
int x=next[j].x,y=next[j].y;
f[i][y]=(f[i][y]+f[i-][x])%mod;
}
printf("%d\n",f[n][]);
}
1007 正整数分组 1010 只包含因子2 3 5的数 1014 X^2 Mod P 1024 矩阵中不重复的元素 1031 骨牌覆盖的更多相关文章
- 51nod 1010 只包含因子2 3 5的数 二分答案
1010 只包含因子2 3 5的数 K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 > ...
- 51nod 1010 只包含因子2 3 5的数 打表
只包含因子2 3 5的数 题目连接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 Description K的 ...
- 51Nod 1010 只包含因子2 3 5的数 Label:None
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 51Nod 1010 只包含因子2 3 5的数
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 51Nod 1010 只包含因子2 3 5的数(打表+二分)
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 51Nod 1010 只包含因子2 3 5的数 | 预处理+二分
Input示例 5 1 8 13 35 77 Output示例 2 8 15 36 80 分析:将所有的只含有2 3 5因子的数打一个表保存在一个数组里,然后二分查找第一个>=数组里的数,输出 ...
- 51nod 1010 只包含因子2 3 5的数 && poj - 1338 Ugly Numbers(打表)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 http://poj.org/problem?id=1338 首先 ...
- 只包含因子2 3 5的数(51NOD 1010)
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 51 Nod 1007 正整数分组【类01背包】
1007 正整数分组 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 2 4分为1组, ...
随机推荐
- linux下tomcat作为daemon进程运行
在linux下如果想让tomcat在开机时自启动,可以将启动代码写到/etc/rc.local里面.但是,这样的话,tomcat将以root权限运行,这是不安全的.因此,要想办法让tomcat以非特权 ...
- 『HTMl5』学习日志
w3g提供在线校验页面:http://validator.w3.org/ 1.文本框获取焦点 <%@ page language="java" import="ja ...
- python3 requests 获取 拉勾工作数据
#-*- coding:utf-8 -*- __author__ = "carry" import requests,json for x in range(1, 15): url ...
- 10分钟学会ES7+ES8
撰文为何 身为一个前端开发者,ECMAScript(以下简称ES)早已广泛应用在我们的工作当中.了解ECMA机构流程的人应该知道,标准委员会会在每年的6月份正式发布一次规范的修订,而这次的发布也将作为 ...
- spring mvc:exclude-mapping错误提示
今天搭建一个java web项目时,增加了一个登录的拦截器,主要功能就是未登录的用户无法访问系统的任何页面. 先说明下我的web项目springmvc的版本以及刚开始配置的拦截器: springmvc ...
- 浅析SQL Server在可序列化隔离级别下,防止幻读的范围锁的锁定问题
本文出处:http://www.cnblogs.com/wy123/p/7501261.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...
- 手机端rem适应
这段时间做了几个手机版的项目,因为没有用框架,所以用rem来做适应,下面就分享一下 //第一种是比较简单的代码 (function(win) { resizeRoot(); function resi ...
- !Web云笔记--HTML基础
Web自学笔记第一阶段笔记综合汇总 参考资料:<Head First HTML&CSS>(中文第二版)(美国)弗里昂ISBN:9787508356464 中国电力出版社 全部阶段: ...
- MongoDB学习之路(三)
数据库 一个MongoDB可以建立多个数据库. MongoDB的默认数据库为"db",该数据库存储在data目录中. MongoDB的单个实例可以容纳多个独立的数据库,每一个都有自 ...
- 团队作业4——第一次项目冲刺 FiRsT DaY
项目冲刺--first blood 今天是阳光明媚的一天[明明是阴天好吗= =],今天是心情愉悦的一天[每天都要提交博客高兴个水水哦-3-] 天霸动霸.tua小队迎来了第一敏捷冲刺,小伙伴们是时候打起 ...