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. POJ-1065 Wooden Sticks,排序+最长单减子序列!

                                                       Wooden Sticks 题意:有一台机器处理木材,最开始需要一分钟准备,如果后面处理的木材比前 ...

  2. J2EE 中间件 JVM 集群

    [转]J2EE 中间件 JVM 集群 博客分类: 企业应用面临的问题 Java&Socket 开源组件的应用 jvm应用服务器weblogicjvm集群 1 前言 越来越多的关键任务和大型应用 ...

  3. 【Luogu】P1330封锁阳光大学(bfs染色)

    题目链接 这题恶心死我了. bfs染色,统计每个联通块两色的个数,ans加它们的最小值. #include<cstdio> #include<cctype> #include& ...

  4. [luoguP2862] [USACO06JAN]把牛Corral the Cows(二分 + 乱搞)

    传送门 可以二分边长 然后另开两个数组,把x从小到大排序,把y从小到大排序 枚举x,可以得到正方形的长 枚举y,看看从这个y开始,往上能够到达多少个点,可以用类似队列来搞 其实发现算法的本质之后,x可 ...

  5. java面试题之能创建volatile数组吗?

    答:能,只不过只是一个指向数组的引用,而不是整个数组,如果改变了引用指向的数组,将会受到volatile的保护,但是如果多个线程同时改变数组的元素,volatile关键字就不能起到保护的作用.

  6. NCCloud 指令示例

    http://ansrlab.cse.cuhk.edu.hk/software/nccloud/ Implementation of NCCloud in C++ (updated: August 2 ...

  7. POJ 2762 Going from u to v or from v to u? Tarjan算法 学习例题

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17104   Accepted: 4594 Description In o ...

  8. 球形空间产生器 BZOJ 1013

    球形空间产生器 [问题描述] 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便 ...

  9. java面

    常被问到的十个 Java 面试题 每周 10 道 Java 面试题 : 面向对象, 类加载器, JDBC, Spring 基础概念 Java 面试题问与答:编译时与运行时 java面试基础1 java ...

  10. ci框架——辅助函数

    辅助函数:application/helper下面.命名要求为***_helper.php;这样在调用的时候直接$this->load->helper('***');若想给自定义的辅助函数 ...