TC SRM 582 DIV 2
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的更多相关文章
- TC SRM 584 DIV 2
第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...
- SRM 582 Div II Level One: SemiPerfectSquare
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <ios ...
- SRM 582 Div II Level Two SpaceWarDiv2
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 #include <iostream> # ...
- SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意 ...
- TC SRM 583 DIV 2
做了俩,rating涨了80.第二个题是关于身份证的模拟题,写的时间比较长,但是我认真检查了... 第三个题是最短路,今天写了写,写的很繁琐,写的很多错. #include <cstring&g ...
- 【TC SRM 718 DIV 2 B】Reconstruct Graph
[Link]: [Description] 给你两个括号序列; 让你把这两个括号序列合并起来 (得按顺序合并) 使得组成的新的序列为合法序列; 即每个括号都能匹配; 问有多少种合并的方法; [Solu ...
- 【TC SRM 718 DIV 2 A】RelativeHeights
[Link]: [Description] 给你n个数字组成原数列; 然后,让你生成n个新的数列a 其中第i个数列ai为删掉原数列中第i个数字后剩余的数字组成的数列; 然后问你这n个数列组成的排序数组 ...
- TopCoder SRM 582 Div 1 - Problem 1000 SemiPerfectPower
首先我们可以把答案差分,那么我们只需要求出\(1\)~\(x\)范围内的满足条件的数即可. 题目要求的应该是这个东西的个数: \(l \leq a*b^c \leq r(1 \le a < b) ...
- Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1
据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...
随机推荐
- Leetcode 373.查找和最小的k对数字
查找和最小的k对数字 给定两个以升序排列的整形数组 nums1 和 nums2, 以及一个整数 k. 定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2. 找到和最小的 ...
- Codeforces Round #362 (Div. 2)
闲来无事一套CF啊,我觉得这几个题还是有套路的,但是很明显,这个题并不难 A. Pineapple Incident time limit per test 1 second memory limit ...
- “玲珑杯”ACM比赛 Round #11 " ---1097 - 萌萌哒的第二题
1097 - 萌萌哒的第二题 题意:中文题好像没有必要说题意了吧.. 思路:我们知道由于运输桥不能交叉,所以从右往左所修建的桥的序号是严格单增的.但是每个工厂B有6种选择,只能选一个求最多能建造几座桥 ...
- PTA 10-排序5 PAT Judge (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/677 5-15 PAT Judge (25分) The ranklist of PA ...
- 算法复习——无源汇可行流(zoj2314)
题目: The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nucl ...
- leetcode 349 map
只需要用map来标记1,今儿通过map的值来得到重叠的部分 class Solution { public: vector<int> intersection(vector<int& ...
- 【bzoj1299】[LLH邀请赛]巧克力棒 博弈+模拟
Description TBL和X用巧克力棒玩游戏.每次一人可以从盒子里取出若干条巧克力棒,或是将一根取出的巧克力棒吃掉正整数长度.TBL先手两人轮流,无法操作的人输. 他们以最佳策略一共进行了10轮 ...
- objective-c中#import和@class的区别
在Objective-C中,可以使用#import和@class来引用别的类型, 但是你知道两者有什么区别吗? @class叫做forward-class, 你经常会在头文件的定义中看到通过@cla ...
- js动态适配移动端font-size,单位:rem
比如:目前我手中有一张psd图,大小为640*1010,适配苹果5的手机. 方法步骤: 1.我采用font-size=10px为640*1010手机的初始像素大小: 1rem=10px: 此时psd ...
- T1164 统计数字 codevs
http://codevs.cn/problem/1164/ 题目描述 Description [问题描述]某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*109).已知不 ...