睡前过一道,睡觉睡得香

不管这题多简单,咔咔
按照木块的长度或质量排序,之后贪心即可,后面和NOIP的拦截导弹一样。
我的做法是枚举最远到达的湖,减去相应的时间后贪心。
贪心时需要建立一个堆,用了STL中的priority_queue,然后就不知道如何设置less<>方法了。。。
最后是通过自定义一个类node解决的
一开始写的operator<方法逻辑上有问题,VS 2005跑了一会儿就冒出个 Debug assert error,这个挺赞的
导致我WA的几个数据:
1) 收益为0的几组数据。由于一开始设置的max值为0,因此当正解也是0时并没有记录下当前的最优解。max初始为负值即可。
2) 同样是0导致的问题。0收益的钓鱼点也可能出现在堆中,此时应该放弃这个点,把时间保留给序数大的钓鱼点。
另外我有这次比赛的测试数据和标程,需要的朋友留言即可。
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>

using namespace std;


class node
{
public:
int first, second;

node(int x, int y)

{
first = x;
second = y;
}

bool operator< (const node &rhs) const

{
if (second < rhs.second)
return true;
else if (second > rhs.second)
return false;
else return (first > rhs.first);
}
};


int main()


{
int n, h;
int d[26], t[26], f[26];
priority_queue<node, vector<node>, less<vector<node>::value_type> > heap;
vector<int> best(26);
cin >> n;

while (true)
{
if (n == 0) break;
cin >> h;
for (int i = 1; i <= n; i++)
cin >> f[i];

for (int i = 1; i <= n; i++)
cin >> d[i];

t[0] = 0;
for (int i = 1; i < n; i++)
cin >> t[i];

best.clear();
int max = -1;
// i indicates the last lake

for (int i = 1; i <= n; i++)
{
vector<int> tempBest(26);
int valueGet = 0;
int timeLeft = h * 12;
for (int j = 1; j <= i; j++)
timeLeft -= t[j - 1];

if (timeLeft <= 0) break;
while (!heap.empty())
heap.pop();

for (int j = 1; j <= i; j++)
heap.push(node(j, f[j]));


while ((!heap.empty()) && (timeLeft > 0))
{
int next = heap.top().first;

if (heap.top().second > 0)
{
timeLeft--;
tempBest[next]++;
valueGet += heap.top().second;
}
int valueLeft = heap.top().second - d[next];
heap.pop();
if (valueLeft > 0)
heap.push(node(next, valueLeft));
}

if (valueGet > max)
{
max = valueGet;
best = tempBest;
if (timeLeft > 0)
best[1] += timeLeft;
}
}
printf("%d", best[1] * 5);
for (int i = 2; i <= n; i++)
printf(", %d", best[i] * 5);
printf("\nNumber of fish expected: %d\n", max);
cin >> n;
if (n != 0) cout << endl;
}
return 0;
}

安装samba服务可以与Windows进行文件的共享
下面是在Arch下的简单安装方法:
- pacman -Sy samba
- (root) cp /etc/samba/smb.conf.default /etc/samba/smp.conf
- (root) vim /etc/samba/smb.conf (或者使用其他的编辑器)
[globle]选项块
workgroup = HOME # 组名,在Windows中默认是MSHOME或者WORKGROUP
netbios name = ZelluX # 在网上邻居中显示的机器名
encrypt passwords = yes # 应该设为yes。但是如果要在Windows 98/95上访问你的服务器,得把这个设为no,因为它们不支持密码的加密传输。
[homes]选项块
最简单的配置(登陆后方可访问):
browseable = no
read only = no # 或者writable = yes
匿名可读,登陆后可以修改:
public = yes
writable = yes
write list = @staff
如果想让Windows用户看到一个清晰的目录(隐藏.开头的文件,比如~/.bashrc):
[homes]
path = /home/%u/smb
browseable = no
read only = no
同时要在每位用户的主目录下建立一个smb目录。可以通过在/etc/skel目录下建立smb,从而自动在所有用户目录下建立该目录
mkdir /etc/skel/smb
要共享其他的目录也很容易,只要设置path和valid users属性即可
[music]
path = /mnt/windows/Music/
browseable = yes
read only = yes
valid users = Bryan, Michael, David, Jane
valid users属性指定登陆后有权限访问到这个目录的用户
- (root) 使用 smbpasswd -a 用户名 增加允许登陆的用户,并指定他们的登陆密码
- (root) /etc/rc.d/samba stop 停止samba服务
- (root) /etc/rc.d/samba start 启动samba服务
刚做完了Java课布置的homework,其中有一题是打印日历
February 2007
---------------------------
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28
用GregorianCalendar类几分钟就做好了
Java的确很方便,主要是很多库都集成在jdk中,查一份手册就可以使用
如果这个用C++写,除非去找个开源的库,否则估计就得自己计算了,印象中日期方面的竞赛题都属于难度不大,但是很容易出错的题目。
话虽如此,还是想学好C++ -,-|||