Rating又跌了,第二个题,没想好就乱开始乱写了。。

我写乱搞贪心,没过。。。如果总人数很多judge函数写的不好,DIV2数据很水,直接暴力就行。

 #include <cstring>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int>::iterator it;
int p[],dp[],o[],n,m;
struct node
{
int s,num;
}d[];
int cmp(node a,node b)
{
return a.s < b.s;
}
int judge(int x)
{
int i,j;
for(i = ;i < n;i ++)
dp[i] = x;
for(i = ;i < m;i ++)
{
o[i] = d[i].num;
}
j = n-;
for(i = m-;i >= ;i --)
{
while(o[i])
{
if(j < ) return ;
else if(p[j] >= d[i].s&&dp[j] > )
{
dp[j] --;
if(dp[j] == )
j --;
}
else if(p[j] < d[i].s)
return ;
o[i] --;
}
}
return ;
}
class SpaceWarDiv2
{
public:
int minimalFatigue(vector <int> magicalGirlStrength, vector <int> enemyStrength, vector <int> enemyCount)
{
int i;
n = ;
memset(dp,,sizeof(dp));
for(it = magicalGirlStrength.begin(); it != magicalGirlStrength.end(); it ++)
{
p[n++] = *it;
}
m = ;
for(it = enemyStrength.begin(); it != enemyStrength.end(); it ++)
{
d[m++].s = *it;
}
m = ;
for(it = enemyCount.begin(); it != enemyCount.end(); it ++)
{
d[m++].num = *it;
}
sort(p,p+n);
sort(d,d+m,cmp);
if(p[n-] < d[m-].s) return -;
for(i = ;;i ++)
{
if(judge(i))
return i;
}
}
};

第三题爆搜,看了一下,有人说,直接暴力+确定一个上界就可以了,然后我写了写,加了很多剪枝(有几个剪枝都是应该是正确的,其实我也不知道正确性),终于过了。。。

 #include <cstring>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int>::iterator it;
int flag[],p[];
int minz,n;
void dfs(int x,int step,int num)
{
int i,s;
if(step > minz)
return ;
if(num > *n)//移动次数不能很多
return ;
s = ;
for(i = ;i < n;i ++)
{
if(!flag[i])
{
s = ;
break;
}
}
if(s == )
{
minz = min(minz,step);
return ;
}
if(x == )
{
if(!flag[x+])//擦右边
{
flag[x+] = step++p[x+];
dfs(x,step+,num);
flag[x+] = ;
}
if(step >= flag[x+])//往右边移动
{
dfs(x+,step+,num+);
}
if(flag[x+]&&step < flag[x+])
{
dfs(x,flag[x+],num);//停留
}
}
else if(x == n-)
{
if(!flag[x-])//擦左边
{
flag[x-] = step++p[x-];
dfs(x,step+,num);
flag[x-] = ;
}
if(step >= flag[x-])
{
dfs(x-,step+,num+);
}
if(flag[x-]&&step < flag[x-])
{
dfs(x,flag[x-],num);//停留
}
}
else
{
if(!flag[x+])//擦右边
{
flag[x+] = step++p[x+];
dfs(x,step+,num);
flag[x+] = ;
}
if(!flag[x-])//擦左边
{
flag[x-] = step++p[x-];
dfs(x,step+,num);
flag[x-] = ;
}
if(step >= flag[x+])//往右边移动
{
dfs(x+,step+,num+);
}
if(step >= flag[x-])
{
dfs(x-,step+,num+);
}
if(flag[x-]&&step < flag[x-])
{
dfs(x,flag[x-],num);//停留
}
if(flag[x+]&&step < flag[x+])
{
dfs(x,flag[x+],num);//停留
}
}
}
class ColorTheCells
{
public:
int minimalTime(vector <int> dryingTime)
{
int sum;
sum = ;
for(it = dryingTime.begin();it != dryingTime.end();it ++)
{
p[n++] = *it;
sum = min(sum,*it);
}
sum += n*;//定住上界
minz = sum;
dfs(,,);
return minz;
}
};

TC SRM 582 DIV 2的更多相关文章

  1. TC SRM 584 DIV 2

    第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...

  2. SRM 582 Div II Level One: SemiPerfectSquare

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <ios ...

  3. SRM 582 Div II Level Two SpaceWarDiv2

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 #include <iostream> # ...

  4. SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意  ...

  5. TC SRM 583 DIV 2

    做了俩,rating涨了80.第二个题是关于身份证的模拟题,写的时间比较长,但是我认真检查了... 第三个题是最短路,今天写了写,写的很繁琐,写的很多错. #include <cstring&g ...

  6. 【TC SRM 718 DIV 2 B】Reconstruct Graph

    [Link]: [Description] 给你两个括号序列; 让你把这两个括号序列合并起来 (得按顺序合并) 使得组成的新的序列为合法序列; 即每个括号都能匹配; 问有多少种合并的方法; [Solu ...

  7. 【TC SRM 718 DIV 2 A】RelativeHeights

    [Link]: [Description] 给你n个数字组成原数列; 然后,让你生成n个新的数列a 其中第i个数列ai为删掉原数列中第i个数字后剩余的数字组成的数列; 然后问你这n个数列组成的排序数组 ...

  8. TopCoder SRM 582 Div 1 - Problem 1000 SemiPerfectPower

    首先我们可以把答案差分,那么我们只需要求出\(1\)~\(x\)范围内的满足条件的数即可. 题目要求的应该是这个东西的个数: \(l \leq a*b^c \leq r(1 \le a < b) ...

  9. Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1

    据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...

随机推荐

  1. 九度oj 题目1100:最短路径

    题目描述: N个城市,标号从0到N-1,M条道路,第K条道路(K从0开始)的长度为2^K,求编号为0的城市到其他城市的最短距离 输入: 第一行两个正整数N(2<=N<=100)M(M< ...

  2. 原生 ajax get请求数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. USACO Hamming Codes

    题目大意:求n个两两hamming距离大于等于d的序列,每个元素是一个b bit的数 思路:仍然暴力大法好 /*{ ID:a4298442 PROB:hamming LANG:C++ } */ #in ...

  4. VMware---之网卡设置

    闲来无事,扯点皮,详细说下NAT配置过程 NAT全称Network Address Translation网络地址转换,顾名思义,配置的重点也是地址转换. 步骤1.配置局域网段及网关 打开vmware ...

  5. 解决 IDEA 中src下xml等资源文件无法读取的问题

    该问题的实质是,idea对classpath的规定. 在eclipse中,把资源文件放在src文件夹下,是可以找到的: 但是在idea中,直接把资源文件放在src文件夹下,如果不进行设置,是不能被找到 ...

  6. Spell Boost

    Spell Boost 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Shadowverse is a funny card game. One day you are playing ...

  7. POJ 3585 Accumulation Degree

    二次扫描与换根法 用于解决无根树,对于每一个节点作为根时都要统计 做法: 1.先以任意一个节点为根,做树形DP,保存每个节点的DP值 2.然后自上而下dfs,对于每个节点考虑以他为根的最大值 #inc ...

  8. 对Netflix Ribbon的Loadbalancer类源码设计合理性的一点质疑

    首先,这只是我个人的一点质疑,可能是因为我自己菜没有领悟到作者的意思,也正因此,想发出来跟大家一起探讨. 在昨晚,我因为在编写自己的开源项目的负载均衡模块(这是我开源项目的介绍:https://www ...

  9. ZOJ 3811 / 2014 牡丹江赛区网络赛 C. Untrusted Patrol bfs/dfs/并查集

    Untrusted Patrol Time Limit: 3 Seconds                                     Memory Limit: 65536 KB    ...

  10. compose.yml模板文件

    默认的模板文件名称为 docker-compose.yml,格式为 YAML 格式. 示例: version: " services: webapp: image: examples/web ...