| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
用g++编译时memset引用哪个库?还有1014 OLE问题如果程序中要使用memset,只#include<iostream>肯定是不好使的。如果#include<cstdlib>在c++下编译能过,在g++上则不行。不知道如何include能在g++下编译通过。
另外,在做1014题的时候莫名奇妙output limit exceeded. 我的代码是完全按照题意输出的。如果哪位高手能找到问题请不吝赐教。代码如下:
(动态规划)
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int reach[60050];
int data[7];
int sum;
void fillreach(){
int i,j,k,false_count,half_sum;
half_sum = sum/2;
for(i=1;i<=6;i++){
if(data[i] == 0)continue;
false_count=0;
for(j=0;j<=half_sum-i;j++){
if(j==0 || reach[j]>0 && reach[j] != i){
for(k=1;k<=data[i];k++){
if(j+k*i <= half_sum && reach[j+k*i] == 0)
reach[j+k*i]=i;
}
}
else{
false_count++;
if(false_count > i)break;
}
}
}
}
bool test(){
if(sum % 2 != 0)return false;
fillreach();
if(reach[sum/2] > 0)return true;
return false;
}
int main(){
int i,count;
count=1;
while(1){
sum=0;
for(i=1;i<=6;i++){
cin >> data[i];
sum += i*data[i];
}
if(sum == 0)break;
memset(reach,0,sizeof(reach));
cout << "Collection #" << count << ":" << endl;
if(test()){
cout << "Can be divided." << endl;
}
else{
cout << "Can't be divided." << endl;
}
cout << endl;
count++;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator