int main(int argc, char const* argv[]) { std::string expr; if(argc == 1) { std::cerr << "usage : " << argv[0] << " expr\n"; return 1; } if(argc == 2) { expr = argv[1]; } std::vector<std::string> paths = harvest(expr); std::cout << "Matches:\n"; for(std::size_t i = 0; i < paths.size(); ++i) { std::cout << paths[i] << std::endl; } return 0; }
int main(){ const long N = 3000; std::vector<long> harvest(N + 2, 0); long n, v; scanf("%ld %ld", &n, &v); for(int p = 0; p < n; p++){ long day, fruit; scanf("%ld %ld", &day, &fruit); harvest[day] += fruit; } long carry(0); for(int p = 1; p <= N + 1; p++){ harvest[p] += carry; if(harvest[p] > v){carry = harvest[p] - v; harvest[p] = v;} else{carry = 0;} if(carry > v){carry = v;} } long total(0); for(long p = 0; p < harvest.size(); p++){total += harvest[p];} printf("%ld\n", total); return 0; }
int main(){ const long N = 3000; std::vector<long> harvest(N + 2, 0); long n, v; scanf("%ld %ld", &n, &v); for(long p = 0; p < n; p++){ long a, b; scanf("%ld %ld", &a, &b); long capacity = v - harvest[a]; if(b <= capacity){harvest[a] += b; b = 0;} else{harvest[a] = v; b -= capacity;} harvest[a + 1] += b; if(harvest[a + 1] > v){harvest[a + 1] = v;} } long total(0); for(long p = 0; p < harvest.size() ; p++){total += harvest[p];} printf("%ld\n", total); return 0; }
int main(int argc, char **argv) { int i; int threads; if (parse_args(argc, argv) == -1) return 1; if (mix_it_up) threads = NumFloatThreads + NumIntThreads; else threads = NumFloatThreads > NumIntThreads ? NumFloatThreads : NumIntThreads; ack = new int[threads]; if (!ack) W_FATAL(fcOUTOFMEMORY); worker = new sthread_t *[threads]; if (!worker) W_FATAL(fcOUTOFMEMORY); for (i=0; i<NumIntThreads; ++i) { ack[i] = 0; worker[i] = new int_thread_t(i); w_assert1(worker[i]); W_COERCE( worker[i]->fork() ); } if (!mix_it_up) harvest(NumIntThreads); int base = mix_it_up ? NumIntThreads : 0; for(i=base ; i < base + NumFloatThreads; ++i){ ack[i] = 0; worker[i] = new float_thread_t(i); w_assert1(worker[i]); W_COERCE( worker[i]->fork() ); } harvest(mix_it_up ? threads : NumFloatThreads); delete [] worker; delete [] ack; return 0; }
~ProcHarvester() { try { harvest(); } catch(...) {} m_procs.clear(); }
void Crop::kill (const symbol name, const Time& time, const Geometry& geo, std::vector<AM*>& residuals, double& residuals_DM, double& residuals_N_top, double& residuals_C_top, std::vector<double>& residuals_N_soil, std::vector<double>& residuals_C_soil, Treelog& out) { harvest (name, time, geo, 0.0, 0.0, 0.0, 0.0, true, residuals, residuals_DM, residuals_N_top, residuals_C_top, residuals_N_soil, residuals_C_soil, false, out); }
TEST (ThreadTest3, All) { int i; int threads; if (mix_it_up) threads = NumFloatThreads + NumIntThreads; else threads = NumFloatThreads > NumIntThreads ? NumFloatThreads : NumIntThreads; ack = new int[threads]; EXPECT_TRUE (ack != NULL); worker = new sthread_t *[threads]; EXPECT_TRUE (worker != NULL); for (i=0; i<NumIntThreads; ++i) { ack[i] = 0; worker[i] = new int_thread_t(i); EXPECT_TRUE (worker[i] != NULL); EXPECT_FALSE( worker[i]->fork().is_error() ); } if (!mix_it_up) harvest(NumIntThreads); int base = mix_it_up ? NumIntThreads : 0; for(i=base ; i < base + NumFloatThreads; ++i){ ack[i] = 0; worker[i] = new float_thread_t(i); EXPECT_TRUE (worker[i] != NULL); EXPECT_FALSE( worker[i]->fork().is_error()); } harvest(mix_it_up ? threads : NumFloatThreads); delete [] worker; delete [] ack; }
apr_status_t gpdb_harvest_one(const char* table) { return harvest(table, NULL, NULL); }
int main(int argc, char* argv[]) { struct prg_data prg; struct sigListenConfig lconf; prg.sigData = calloc( 1, sizeof(struct sig_data) ); prg.mediaCnf = calloc( 1, sizeof(struct mediaConfig) ); /* struct mediaConfig mconf; */ /* struct addrinfo servinfo, * p; */ /* Intializes random number generator */ time_t t; srand( (unsigned) time(&t) ); /* struct sockaddr_storage taddr; */ /* Set up the pointer(s).. */ lconf.prg = &prg; /* lconf.mconf = &mconf; */ pthread_t sigSocketListenThread; pthread_t stunTickThread; pthread_t iceTickThread; /* pthread_t turnTickThread; */ if (argc < 3) { fprintf(stderr,"usage: icebox hostname user remoteuser\n"); exit(1); } lconf.sigsock = createTcpSocket(argv[1], SERVERPORT); lconf.signal_path_handler = signalPathHandler; /* lconf.msock = createUdpSocket(argv[1], */ /* STUNPORT, */ /* "turnclient", */ /* 0, */ /* &servinfo, */ /* &p); */ /* if (lconf.msock == -1) */ /* { */ /* return 1; */ /* } */ /* else if (lconf.msock == -2) */ /* { */ /* return 2; */ /* } */ pthread_create(&sigSocketListenThread, NULL, sigSocketListen, (void*)&lconf); strncpy(prg.user, argv[2], MAX_USER_LEN); registerUser(&prg.sigData->state, lconf.sigsock, prg.user); /* Setup ICE */ ICELIB_CONFIGURATION iceConfig; iceConfig.tickIntervalMS = 20; iceConfig.keepAliveIntervalS = 15; iceConfig.maxCheckListPairs = ICELIB_MAX_PAIRS; iceConfig.aggressiveNomination = false; iceConfig.iceLite = false; iceConfig.logLevel = ICELIB_logDebug; /* iceConfig.logLevel = ICELIB_logDisable; */ prg.mediaCnf->icelib = malloc( sizeof(ICELIB_INSTANCE) ); ICELIB_Constructor(prg.mediaCnf->icelib, &iceConfig); /* ICELIB_setCallbackLog(prg.mediaCnf->icelib, */ /* ICELIB_printLog, */ /* NULL, */ /* ICELIB_logDebug); */ ICELIB_setCallbackOutgoingBindingRequest(prg.mediaCnf->icelib, sendConnectivityCheck, &prg); ICELIB_setCallbackOutgoingBindingResponse(prg.mediaCnf->icelib, sendConnectivityResp, &prg); ICELIB_setCallbackConnecitivityChecksComplete(prg.mediaCnf->icelib, complete, &prg); ICELIB_setCallbackNominated(prg.mediaCnf->icelib, nominated, &prg); ICELIB_setCallbackOutgoingCancelRequest(prg.mediaCnf->icelib, cancelSTUNtrans, &prg); /* Setup stun */ StunClient_Alloc(&prg.mediaCnf->stunInstance); /* StunClient_RegisterLogger(prg.mediaCnf->stunInstance, */ /* stunLog, */ /* &prg); */ /* Signal path set up, time to gather the candidates */ /* Turn setup */ /* if ( 0 != getSockaddrFromFqdn( (struct sockaddr*)&taddr, argv[1] ) ) */ /* { */ /* printf("Error getting TURN Server IP\n"); */ /* return 1; */ /* } */ /* TurnClient_StartAllocateTransaction(&lconf.turnInst, */ /* 50, */ /* turnInfoFunc, */ /* "icebox", */ /* &lconf.msock, / * *userCtx * / */ /* (struct sockaddr*)&taddr, */ /* / "test\0", / *argv[2],* / */ /* "pass\0", / *argv[2],* / */ /* AF_INET, */ /* turnSendFunc, */ /* turnCbFunc, */ /* false, */ /* 0); */ /* pthread_create(&turnTickThread, NULL, tickTurn, (void*)lconf.turnInst); */ pthread_create(&stunTickThread, NULL, tickStun, (void*)prg.mediaCnf->stunInstance); pthread_create(&iceTickThread, NULL, tickIce, (void*)prg.mediaCnf->icelib); if (argc == 4) { /* Ok got nothing better to do. Busywaiting */ while (prg.sigData->state != REGISTERED) { } char* sdp = NULL; harvest(prg.mediaCnf->icelib); printf("Completed harvesting\n"); crateCandidateJson(prg.mediaCnf->icelib, &sdp); /* Start to listen here.. */ pthread_create(&prg.mediaCnf->mSocketListenThread, NULL, mSocketListen, (void*)prg.mediaCnf); inviteUser(&prg.sigData->state, lconf.sigsock, argv[3], prg.user, sdp); if (sdp != NULL) { free(sdp); } } /* Just wait a bit for now.. */ sleep(100); printf("Done sleeping teardown\n"); close(lconf.sigsock); StunClient_free(prg.mediaCnf->stunInstance); free(prg.mediaCnf); free(prg.sigData->sdp); free(prg.sigData->msgBuf); free(prg.sigData); return 0; }