能把代码写成这样,指定是有点毛病
namespace Ff_c109 {
class Array {
long double* content;
long int Length;
int unitSize;
public:
static const void* deleteErro; //Unable to free memory
static const void* memoryInitializationError; //An error occurred while calling malloc function to allocate space
static const void* pointerConversionError; //Force pointer convert erro
static const void* memoryRWError; //Memory Read or Write Erro
Array(void* a, long int b, int thisUnitSize);
~Array();
Array& operator = (const Array &other);
void* getContent();
long int getArrayLength();
int getUnitSize();
static Array Create(long int b, int thisUnitSize);
};
}
namespace Ff_c109 {
long int VoidToLong(void* object);
void* LongToVoid(long int object);
}
#include <iostream>
using namespace std;
using namespace Ff_c109;
int l, n, k;
Array ln = Array::Create(1, 1);
bool pd(int dis) {
int cont = 0;
for(int i = 0; i <= n; i++) {
if((((int*)ln.getContent())[i + 1]) - (((int*)ln.getContent())[i]) > dis) {
cont += ((((int*)ln.getContent())[i + 1]) - (((int*)ln.getContent())[i]))/dis;
if((((((int*)ln.getContent())[i + 1]) - (((int*)ln.getContent())[i]))) % dis == 0)
cont--;
}
if(cont > k)
return false;
}
return true;
}
int main(int argc, char** argv) {
cin >> l >> n >> k;
ln = Array::Create(n, sizeof(int));
for(int i = 0; i < n; i++) {
cin >> ((int*)ln.getContent())[i];
}
int L = 0, R = 10000003;
((int*)ln.getContent())[0] = 0;
((int*)ln.getContent())[n + 1] = l;
int res;
while(L < R) {
int mid = (L + R) / 2;
if(pd(mid))
R = mid;
else
L = mid + 1;
}
cout << L;
return 0;
}
#include <malloc.h>
#include <exception>
const void* Ff_c109::Array::deleteErro = new void*;
const void* Ff_c109::Array::memoryInitializationError = new void*;
const void* Ff_c109::Array::pointerConversionError = new void*;
const void* Ff_c109::Array::memoryRWError = new void*;
Ff_c109::Array::Array(void* a, long int b, int thisUnitSize) {
auto rollBack = [=] {
try {
delete[] content;
}
catch (void* e) {
throw(Ff_c109::Array::deleteErro);
return;
}
Length = 0;
unitSize = 1;
};
Length = b;
//content = new long double[Length];
try {
content = (long double*)malloc(Length * thisUnitSize);
}
catch (void* e) {
throw(Ff_c109::Array::memoryInitializationError);
return;
}
long double* dump = content;
void* a_dump = a;
for (int i = 0; i < Length; i++) {
try {
*content = *(long double*)a;
}
catch(void* e) {
rollBack();
throw(Ff_c109::Array::memoryRWError);
}
//content++;
//long int contentLocation = (long int)content;
long int contentLocation;
try {
contentLocation = VoidToLong(content);
}
catch (void* e) {
rollBack();
throw(Ff_c109::Array::pointerConversionError);
return;
}
contentLocation += thisUnitSize;
//content = (long double*)contentLocation;
try {
content = (long double*)LongToVoid(contentLocation);
}
catch (void* e) {
rollBack();
throw(Ff_c109::Array::pointerConversionError);
return;
}
//long int location = (long int)a;
long int location = VoidToLong(a);
location += thisUnitSize;
//a = (void*)location;
a = LongToVoid(location);
}
unitSize = thisUnitSize;
content = dump;
a = a_dump;
}
Ff_c109::Array::~Array() {
delete[] content;
Length = 0;
unitSize = 1;
}
Ff_c109::Array& Ff_c109::Array::operator=(const Array &other) {
if (this == &other)
return *this;
try {
delete[] content;
}
catch (void* e) {
throw(Ff_c109::Array::deleteErro);
return *this;
}
Length = 0;
unitSize = 1;
Length = other.Length;
try {
content = (long double*)malloc(Length * other.unitSize);
}
catch (void * e) {
throw(Ff_c109::Array::memoryInitializationError);
return *this;
}
long double* dump = content;
void* other_content_dump = other.content;
for (int i = 0; i < Length; i++) {
try {
*content = *(long double*)other_content_dump;
}
catch (void* e) {
throw(Ff_c109::Array::memoryRWError);
return *this;
}
//content++;
//long int contentLocation = (long int)content;
long int contentLocation;
try {
contentLocation = VoidToLong(content);
}
catch (void* e) {
throw(Ff_c109::Array::pointerConversionError);
return *this;
}
contentLocation += other.unitSize;
//content = (long double*)contentLocation;
try {
content = (long double*)LongToVoid(contentLocation);
}
catch (void* e) {
throw(Ff_c109::Array::pointerConversionError);
return *this;
}
//long int location = (long int)other_content_dump;
long int location;
try {
location = VoidToLong(other_content_dump);
}
catch (void* e) {
throw(Ff_c109::Array::pointerConversionError);
return *this;
}
location += other.unitSize;
//other_content_dump = (void*)location;
try {
other_content_dump = LongToVoid(location);
}
catch (void* e) {
throw(Ff_c109::Array::pointerConversionError);
return *this;
}
}
unitSize = other.unitSize;
content = dump;
return *this;
}
void* Ff_c109::Array::getContent() {
return content;
}
long int Ff_c109::Array::getArrayLength() {
return Length;
}
int Ff_c109::Array::getUnitSize() {
return unitSize;
}
Ff_c109::Array Ff_c109::Array::Create(long int b, int thisUnitSize) {
Ff_c109::Array back(NULL, 0, 0);
back.content = (long double*)malloc(b * thisUnitSize);
back.Length = b;
back.unitSize = thisUnitSize;
return back;
}
long int Ff_c109::VoidToLong(void* object) {
long int res;
void* pointer = &object;
res = *(long int*)pointer;
return res;
}
void* Ff_c109::LongToVoid(long int object) {
void* res;
void* pointer = &object;
res = *(long double**)pointer;
return res;
}