1.http://acm.hdu.edu.cn/showproblem.php?pid=5112

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 100000+10;
struct Node{
int t;
int x;
bool operator<(Node&a){
return t < a.t;
}
};
Node S[MAXN];
int main(){
int i, T,n;
int iCase = 1;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &S[i].t, &S[i].x);
sort(S, S + n);
double Max = 0;
for (i = 0; i < n - 1; i++){
double v = abs(S[i + 1].x - S[i].x)*1.0 / (S[i + 1].t - S[i].t);
Max = max(Max, v);
}
printf("Case #%d: %.2lf\n",iCase++, Max);
}
return 0;
}

  2.http://acm.hdu.edu.cn/showproblem.php?pid=5122

一开始一看到以为求逆序来搞,一看题就写了个数状数组,nlogn超时了。当然一定是太性急了,这个题其实就是判断下它后面是否有数字比它小,有的话需要将其往后移一次,否则不变。这样只需要判断下每个数后面是否有有比它小的数,于是将数组倒置,即为判断每个数前面是否有比它大的数,只需要从前向后扫描一遍,需要一个数Min记录当前已扫描结束的序列中最小的数。这样只要碰到后迷死你右数大于这个最小的数就计数一次,否则更新这个Min。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 10000001;
int a[MAXN];
int main(){
int i, T, n;
int iCase = 1;
scanf("%d", &T);
while (T--){
scanf("%d", &n);
for (i = n; i > 0; i--)
scanf("%d", &a[i]);
int Min = a[1];
int ans = 0;
for (i = 2; i <= n; i++){
if (a[i] > Min)
ans++;
else
Min = a[i];
}
printf("Case #%d: %d\n",iCase++,ans);
}
return 0;
}

  3.http://acm.hdu.edu.cn/showproblem.php?pid=5120

模板很重要啊。这里主要的是求两个圆相交的面积,有了模板直接搞。最终面积=大圆交大圆-2*大圆交小圆+小圆交小圆。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const double EPS = 1e-8;
const double pi = acos(-1.0);
struct Point{
double x, y;
Point(double a=0, double b=0) :x(a), y(b){}
};
struct Circle{
Circle(Point a, double x) :o(a), r(x){}
Point o;
double r;
};
int RlCmp(double r1, double r2){
if (abs(r1 - r2) < EPS)
return 0;
return r1 < r2 ? -1 : 1;
}
Point operator-(Point a, Point b){
return Point(a.x - b.x, a.y - b.y);
}
Point operator+(Point a, Point b){
return Point(a.x + b.x, a.y + b.y);
}
double Mold(Point a){
return sqrt(a.x*a.x + a.y*a.y);
}
double Dis(Point a, Point b){
return Mold(a - b);
}
//园与圆相交面积模板
double CircleCrossArea(Circle A,Circle B){
double r1 = A.r, r2 = B.r;
double d = Dis(A.o, B.o),r=min(r1,r2);
if (RlCmp(d, r1 + r2) >= 0)
return 0; //相离或者外切
if (RlCmp(d, abs(r1 - r2)) <= 0)
return pi*r*r; //内含
//将r1放在圆心
double x1 = (d*d + r1*r1 - r2*r2) / (2 * d);
double s1 = x1*sqrt(r1*r1 - x1*x1) - r1*r1*acos(x1/r1);
//将r2放在圆心
double x2 = (d*d + r2*r2 - r1*r1) / (2 * d);
double s2 = x2*sqrt(r2*r2 - x2*x2) - r2*r2*acos(x2 / r2);
return abs(s1 + s2);
}
int main(){
int T, iCase = 1;
Point q,o;
double r1, r2;
scanf("%d", &T);
while (T--){
scanf("%lf%lf",&r1,&r2);
scanf("%lf%lf",&q.x,&q.y);
scanf("%lf%lf", &o.x,&o.y);
Circle A1(q, r1);
Circle A2(q, r2);
Circle B1(o, r1);
Circle B2(o, r2);
double a = CircleCrossArea(A2, B2);
double b = CircleCrossArea(A2, B1);
double c = CircleCrossArea(A1, B1);
printf("Case #%d: %.6lf\n", iCase++, a - 2 * b + c);
}
return 0;
}

  4.http://acm.hdu.edu.cn/showproblem.php?pid=5113

一个很好的搜索题。对矩阵从左到右,一行一行的进行搜索(不要把回溯写错或者写漏掉.....老毛病).注意剪枝,一个剪枝条件是,当某一种颜色的数量超过(格子总数+1)/2时,剩下颜色拼出的一定是不合法的。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 7;
int a[7][7];
int b[MAXN*MAXN];
int k, n, m,iCase;
int dir[4][2] = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } };
bool ans;
bool isLeg(int x, int y,int val){
//判断在a[x][y]处填颜色val是否合法
return x - 1 >=0 && a[x - 1][y] != val
&&y - 1 >=0 && a[x][y - 1] != val;
}
void DFS(int r,int c,int cur){
for (int i = 1; i <= k; i++){
if (b[i]>(cur+1)/2) //剪枝
return;
}
if (c > m){
c = 1;
r++;
}
if (r > n){
//r>n时,表明已经搜索完成
ans = true;
printf("Case #%d:\nYES\n", iCase++);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
printf(j == m ? "%d\n" : "%d ", a[i][j]);
}
}
if (ans)
return;
for (int i = 1; i <= k; i++){
if (b[i] > 0 && isLeg(r, c, i)){
a[r][c] = i;
b[i]--;
DFS(r, c+1,cur-1);
//记得回溯洛......
b[i]++;
a[r][c] = 0;
}
}
}
int main(){
int T, i,j;
scanf("%d", &T);
iCase = 1;
while (T--){
scanf("%d%d%d", &n, &m,&k);
for (i = 1; i <= k; i++)
scanf("%d", &b[i]);
memset(a, 0, sizeof(a));
ans = false;
DFS(1, 1,n*m);
if (!ans)
printf("Case #%d:\nNO\n", iCase++);
}
return 0;
}

  5.http://acm.hdu.edu.cn/showproblem.php?pid=5119

背包问题,真难看出来....。用dp[i][j]表示前i个数中异或值为j的选法数。则得到状态转移方程dp[i][j]=dp[i-1][j]+dp[i-1][j^a[i]];   这里有一个性质:若a^b=c,则b^c=a,a^c=b;题目还有一个坑点,Mi<=10^6,但是他们的异或值可能会超过10^6,于是数组开在10^6大一点不行,但是开在10^7又会爆掉。考虑到10^6的二进制数异或值不会大于2^20次方,从而可以拿这个数来开数组。另外,第i行只与第i-1行有关,可以使用滚动数组。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 1<<20;
LL n, m;
LL a[45];
LL f[2][MAXN];
int main(){
LL i, iCase, T,j;
iCase = 1;
scanf("%I64d", &T);
while (T--){
scanf("%I64d%I64d", &n, &m);
for (i = 1; i <= n; i++)
scanf("%I64d", &a[i]);
memset(f, 0, sizeof(f));
//从前0个数中选取0个数,异或值等于0,方法有一种,就是什么也不选
f[0][0] = 1;
for (i = 1; i <= n; i++){
for (j=0;j<MAXN; j++){
f[i%2][j] = f[(i-1)%2][j] + f[(i-1)%2][j^a[i]];
}
}
LL ans = 1;
ans <<= n;
for (i =0; i <m;i++)
ans-= f[n%2][i];
printf("Case #%I64d: %I64d\n",iCase++,ans);
}
return 0;
}

  

2016summer 训练第二场的更多相关文章

  1. 大家一起做训练 第二场 E Cottage Village

    题目来源:CodeForce #15 A 现在有 n 间正方形的房子,其中心点分布在 X轴 上,现在我需要新建一间边长为 t 的房子,要求新房子至少和一间房子相邻,但是不能和其他房子重合.请输出我有多 ...

  2. CSU 多校训练第二场 J Pinemi Puzzles

    传送门:http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2279 题意: 代码: #include <set> #incl ...

  3. 2016summer 训练第一场

    A.http://acm.hdu.edu.cn/showproblem.php?pid=5538 求表面积,只需要将所有的1*1的小块扫描一遍.将每一个块与他相邻四周进行比较,如果该快高度大,则将该快 ...

  4. 2015多校训练第二场 hdu5305

    把这题想复杂了,一直在考虑怎么快速的判断将选的边和已选的边无冲突,后来经人提醒发现这根本没必要,反正数据也不大开两个数组爆搜就OK了,搜索之前要先排除两种没必要搜的情况,这很容易想到,爆搜的时候注意几 ...

  5. 18牛客多校训练第二场 J farm

    题意:一个n×m的农田, 每个小格子都有一种作物, 现在喷t次农药,每次农药覆盖一个矩形, 该矩形里面与农药类型不同的植物都会死掉, 求最后植物的死亡数是多少. 题解:二维树状数组. 每次喷农药的时候 ...

  6. 2019HDU多校训练第二场 Longest Subarray

    题意:给你一个串,问满足以下条件的子串中最长的是多长:对于每个数字,要么在这个子串没出现过,要么出现次数超过k次. 思路:对于这类问题,常常转化为数据结构的询问问题.我们考虑枚举右端点,对于当前右端点 ...

  7. 牛客网多校训练第二场D Kth Minimum Clique

    链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...

  8. Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)

    Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...

  9. 2018牛客网暑假ACM多校训练赛(第二场)E tree 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round2-E.html 题目传送门 - 2018牛客多校赛第二场 E ...

随机推荐

  1. hadoop2.5.2学习及实践笔记(一)—— 伪分布式学习环境搭建

    软件 工具:vmware 10 系统:centOS 6.5  64位 Apache Hadoop: 2.5.2  64位 Jdk:  1.7.0_75  64位 安装规划 /opt/softwares ...

  2. PHP命名空间与use

    当在一个大型项目很多程序员书写模板时,最怕出现的问题就是命名,如果一个PHP脚本出现了同名的类或者方法,就会报错(fatal error),使用命名空间可以 解决这个问题 知识点: 命名空间names ...

  3. hdu 2510 符号三角形 (DFS+打表)

    符号三角形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  4. ubuntu服务器环境配置参考

    一.基本的Linux系统命令: ls 查看当前目录下的文件及文件夹 cd /var/www/html 转换目录到/var/www/html cd abc/ddd/ 转换目录到当前目录下的abc文件夹下 ...

  5. IPv4地址分类及特征

    IPv4地址分类及特征 IP地址后斜杠和数字代表的意思 其中有这样一个IP地址的格式:IP/数字,例如:111.222.111.222/24 这种格式平时在内网中用的不多,所以一下子看不懂,最后查了资 ...

  6. H3C交换机端口链路聚合

    H3C交换机端口链路聚合 以太网链路聚合 -- 以太网链路聚合配置命令 -- lacp system-prioritylacp system-priority命令用来配置系统的LACP优先级.undo ...

  7. BZOJ2875 [Noi2012]随机数生成器 【矩阵乘法 + 快速乘】

    题目 栋栋最近迷上了随机算法,而随机数是生成随机算法的基础.栋栋准备使用线性同余法(Linear Congruential Me thod)来生成一个随机数列,这种方法需要设置四个非负整数参数m,a, ...

  8. MFC 加载资源文件里的png

    static bool LoadImageFromResource(IN CImage* pImage, IN UINT nResID, IN LPCWSTR lpTyp) { if ( pImage ...

  9. 创建型设计模式之单例模式(Singleton)

     结构 意图 保证一个类仅有一个实例,并提供一个访问它的全局访问点. 适用性 当类只能有一个实例而且客户可以从一个众所周知的访问点访问它时. 当这个唯一实例应该是通过子类化可扩展的,并且客户应该无需更 ...

  10. pycharm远程登录mysql

    pycharm远程登录mysqlmysql远程登录需要修改配置文件:cd /etc/mysql/mysql.conf.d/sudo vim mysqld.cn修改bing-address=0.0.0. ...