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. 新浪微博error:redirect_uri_mismatch的解决方法 [

  2. SPOJ GSS3 Can you answer these queries III ——线段树

    [题目分析] GSS1的基础上增加修改操作. 同理线段树即可,多写一个函数就好了. [代码] #include <cstdio> #include <cstring> #inc ...

  3. 高一python笔记大全(过会考)

    最初のプログラム xfは.どちらかの試合(しあい)活動(かつどう)に参加して.a秒(aは整数)を使ったのですが.今あなたがひとつ任務を有:分と秒数を出力するください. a=int(input(&quo ...

  4. 【HDOJ5952】Counting Cliques(团,dfs)

    题意:给定一张n点m边的图,求大小为S的团的个数 N ≤ 100,M ≤ 1000,2 ≤ S ≤ 10,保证点的度不超过20 思路:dfs 因为每个点可能不止属于一个极大团,所以不能求出极大团然后计 ...

  5. msp430项目编程52

    msp430综合项目---扩展项目二52 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结

  6. 创建ROS工作空间和包

    一.创建工作空间 mkdir -p ~/openni_ws/src cd ~/openni_ws catkin_make        //在catkin工作空间(openni_ws)下catkin_ ...

  7. 浅谈Java字符串

    从概念上而言,Java字符串就是Unicode字符序列.由于Java没有内置的字符串类型,而是在标准Java类库中提供了一个预定义类String,每个用双引号的括起来的字符串都是String类的一个实 ...

  8. JavaSE的static、final、abstract修饰符

    static :静态常量,静态方法,静态代码块     静态变量:  静态变量属于类的,使用类名来访问,非静态变量是属于对象的,"必须"使用对象来访问.           注意: ...

  9. java设计模式图

    一.什么是设计模式                                                                                           ...

  10. php 求素数的二种方法

    <?php for($i = 2;$i <= 100;$i++) { for($j = 2; $j <= ($r = $i / $j); $j++) { if(($i % $j)== ...