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. HDU——1195Open the Lock(双向BFS)

    Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. RSA工作原理

    摘自:http://www.ruanyifeng.com/blog/2013/07/rsa_algorithm_part_two.html 一.基础数论 1.互质关系 如果两个正整数,除了1以外,没有 ...

  3. [HNOI2008]越狱 (组合数学)

    题目描述 监狱有连续编号为 1-N 的 N 个房间,每个房间关押一个犯人,有 M 种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱. 输入输出 ...

  4. day2之爬取拉勾网

    认证流程 浏览器清空cookies 步骤一 访问拉勾网网站  https://www.lagou.com/ 做了些什么: 以get方式请求"https://www.lagou.com/&qu ...

  5. kubernetes---CentOS7安装kubernetes1.11.2图文完整版

    转载请注明出处:kubernetes-CentOS7安装kubernetes1.11.2图文完整版 架构规划 k8s至少需要一个master和一个node才能组成一个可用集群. 本章我们搭建一个mas ...

  6. 关于事件委托和时间冒泡(以及apply和call的事项)

    搜索事件委托和事件冒泡,网上一大堆乱七八糟的解释,当然意思都对,没毛病. but,真的无聊. 事件冒泡:事件会从点击的元素开始依次向上流出,直到html,遇见事件监听则执行. 事件委托:原因——父元素 ...

  7. EMD距离

    一.场景介绍   最近在研究一个场景:图片质量评分,给一张图片一个预测的分数.   里面提到了用 EMD(Earth Mover’s Distance)算法来评估两张图片之间的分布距离.下面主要讲解下 ...

  8. CKeditor如何实现图片上传功能

    http://makaiyuan.blog.51cto.com/5819595/1049521 如何在数据库中导入excel文件内的数据:http://jingyan.baidu.com/album/ ...

  9. BZOJ——1606: [Usaco2008 Dec]Hay For Sale 购买干草

    http://www.lydsy.com/JudgeOnline/problem.php?id=1606 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1 ...

  10. kafka-0.8.1.1总结

    文件夹 一.         基础篇 1.     开篇说明 2.     概念说明 3.     配置说明 4.     znode分类 5.     kafka协议分类 6.     Kafka线 ...