seed
stringlengths
16
5.99k
id
int64
0
213
int main(int argc, char *argv[]) { yyparse(); return 0; }
100
float getSimpleValue(int pin_x, int pin_y, int pin_z) { float instant_value_x = analogRead(pin_x); float instant_value_y = analogRead(pin_y); float instant_value_z = analogRead(pin_z); float result = sqrt(pow(instant_value_x,2) + pow(instant_value_y,2) + pow(instant_value_z,2)); return result; }
101
void avg_pool_backprop(const T* delta, T* out, const Shape& delta_shape, const Shape& out_shape, const Shape& window_shape, const Strides& window_movement_strides, const Shape& padding_below, const Shape& padding_above, bool include_padding_in_avg_computation) { NGRAPH_SUPPRESS_DEPRECATED_START CoordinateTransform out_transform(out_shape); for (const Coordinate& out_coord : out_transform) { out[out_transform.index(out_coord)] = 0; } CoordinateTransform delta_transform(delta_shape); for (const Coordinate& delta_coord : delta_transform) { size_t img_index = delta_coord[0]; size_t channel = delta_coord[1]; size_t n_image_dimensions = out_shape.size() - 2; Coordinate source_window_transform_start(2 + n_image_dimensions); Coordinate source_window_transform_end(2 + n_image_dimensions); Strides source_window_transform_source_strides(2 + n_image_dimensions, 1); AxisVector source_window_transform_source_axis_order(2 + n_image_dimensions); CoordinateDiff source_window_transform_padding_below(2 + n_image_dimensions); CoordinateDiff source_window_transform_padding_above(2 + n_image_dimensions); source_window_transform_start[0] = img_index; source_window_transform_end[0] = img_index + 1; source_window_transform_start[1] = channel; source_window_transform_end[1] = channel + 1; source_window_transform_padding_below[0] = 0; source_window_transform_padding_below[1] = 0; source_window_transform_padding_above[0] = 0; source_window_transform_padding_above[1] = 0; for (size_t i = 2; i < n_image_dimensions + 2; i++) { size_t window_shape_this_dim = window_shape[i - 2]; size_t movement_stride = window_movement_strides[i - 2]; source_window_transform_start[i] = movement_stride * delta_coord[i]; source_window_transform_end[i] = source_window_transform_start[i] + window_shape_this_dim; source_window_transform_padding_below[i] = padding_below[i - 2]; source_window_transform_padding_above[i] = padding_above[i - 2]; } std::iota(begin(source_window_transform_source_axis_order), end(source_window_transform_source_axis_order), 0); CoordinateTransform source_window_transform(out_shape, source_window_transform_start, source_window_transform_end, source_window_transform_source_strides, source_window_transform_source_axis_order, source_window_transform_padding_below, source_window_transform_padding_above); size_t num_elements_in_window = 0; for (const Coordinate& source_window_coord : source_window_transform) { if (source_window_transform.has_source_coordinate(source_window_coord) || include_padding_in_avg_computation) { num_elements_in_window++; } } for (const Coordinate& source_window_coord : source_window_transform) { if (source_window_transform.has_source_coordinate(source_window_coord)) { size_t out_index = source_window_transform.index(source_window_coord); out[out_index] += delta[delta_transform.index(delta_coord)] / num_elements_in_window; } } } NGRAPH_SUPPRESS_DEPRECATED_END }
102
void setup() { Serial.begin(9600); }
103
static bool getBoolBuffer(cstring buffer) { return buffer[0] == 't' && buffer[1] == 'r' && buffer[2] == 'u' && buffer[3] == 'e'; }
104
void addPark (Park parks[], string parkname, string state, int area, int length) { //adds the park struct type to the array parks[length].parkname = parkname; parks[length].state = state; parks[length].area = area; }
105
int calc_get_var(const char *s, int *val) { var_map::iterator it = calc_var_map.find(s); if (it != calc_var_map.end()) { *val = it->second; return 0; } else { std::cerr << "variable " << s << " is not set" <<std::endl; return -1; } }
106
void blinker() { for (int i=0; i<5; i++) { // 10 digitalWrite(led, LOW); delay(100); digitalWrite(led, HIGH); delay(100); } }
107
int main() { int no_of_test_cases; cin >> no_of_test_cases; while(no_of_test_cases--) solve(); return 0; }
108
void myOnDraw(Display* d) { cout << "Display" << endl; }
109
int main(int argc, char *argv[]){ m_error_t res; size_t tests, errors; tests = errors = 0; try { Forker Mother; printf("Test %d: InetStreamSocket CTROR\n",++tests); InetStreamSocket socket; puts("+++ CTOR finished OK!"); printf("Test %d: InetStreamSocket::hostname()\n",++tests); res = socket.hostname("localhost"); if(ERR_NO_ERROR != res){ errors++; printf("*** Error: hostname() failed 0x%.4x\n",(int)res); } else { puts("+++ hostname() finished OK!"); } const unsigned short pNum = 60179; printf("Test %d: InetStreamSocket::port()\n",++tests); res = socket.port(pNum); if(ERR_NO_ERROR != res){ errors++; printf("*** Error: port() failed 0x%.4x\n",(int)res); } else { puts("+++ port() finished OK!"); } printf("Test %d: InetStreamSocket::ipv4()\n",++tests); unsigned long ip = socket.ipv4(); // 127.0.0.1 const unsigned long loc_ip = (127 << (3*8)) + 1; if((ip != loc_ip) || (pNum != socket.port())){ errors++; printf("*** Error: Wrong address %d.%d.%d.%d:%d\n", (int)((ip >> (3*8)) & 0xff), (int)((ip >> (2*8)) & 0xff), (int)((ip >> (1*8)) & 0xff), (int)((ip >> (0*8)) & 0xff), socket.port()); } else { printf("??? Address %d.%d.%d.%d:%d\n", (int)((ip >> (3*8)) & 0xff), (int)((ip >> (2*8)) & 0xff), (int)((ip >> (1*8)) & 0xff), (int)((ip >> (0*8)) & 0xff), socket.port()); puts("+++ ipv4() finished OK!"); } // Setup pipe for syncronizing server and client int pfd[2]; if(::pipe(pfd)){ printf("*** Error: pipe() failed %d\n",errno); perror("*** System Error"); mgrThrow(ERR_FILE_OPEN); } pid_t child = -1; res = Mother.fork( child ); if(res != ERR_NO_ERROR){ printf("*** Error: fork() failed 0x%.4x\n",(int)res); perror("*** System Error"); } else { if(child == 0){ res = do_client(socket,pfd[0],tests,errors); printf("+++ Client exits 0x%.4x\n",(int)res); } else { res = do_server(socket,pfd[1],tests,errors,child); printf("+++ Server exits 0x%.4x\n",(int)res); res = Mother.wait(5000); if(ERR_CANCEL == res){ puts("*** Have Zombies - kill'em"); if(ERR_NO_ERROR == Mother.killChildren()){ res = Mother.wait(1000); if(res != ERR_NO_ERROR) printf("*** Error killing Zombies 0x%.4x\n",(int)res); } } printf("+++ Mother exits 0x%.4x\n",(int)res); printf("Used version: %s\n",socket.VersionTag()); } } } catch(Exception& e){ printf("*** Caught mgr::Exception: %s\n",e.what()); } return 0; }
110
int main() { int start1, start2, n; scanf("%d%d%d", &start1,&start2, &n); for(int i = 0; i < n; i++) { int add, nt; char c; scanf("%d %c %d", &add, &c, &nt); node n1 = {c, nt}; arr[add] = n1; } set<int> s1; int i1 = start1; while(i1 != -1) { s1.insert(i1); i1 = arr[i1].next; } int i2 = start2; while(i2 != -1) { if(s1.find(i2) != s1.end()) { printf("%d", i2); return 0; } else { i2 = arr[i2].next; } } if(i2 == -1) printf("-1"); return 0; }
111
void sumofpzem() { Serial.println("Sum of all 3 PZEM devices"); sum_of_voltage = (voltage_usage_1 + voltage_usage_2 + voltage_usage_3); sum_of_current = (current_usage_1 + current_usage_2 + current_usage_3); sum_of_power = (active_power_1 + active_power_2 + active_power_3); sum_of_active_energy = (active_energy_1 + active_energy_2 + active_energy_3); sum_of_frequency = (frequency_1 + frequency_2 + frequency_3); sum_of_power_factor = (power_factor_1 + power_factor_2 + power_factor_3); Serial.print("SUM of VOLTAGE: "); Serial.println(sum_of_voltage); // V Serial.print("SUM of CURRENT_USAGE: "); Serial.println(sum_of_current, 3); // A Serial.print("SUM of ACTIVE_POWER: "); Serial.println(sum_of_power); // W Serial.print("SUM of ACTIVE_ENERGY: "); Serial.println(sum_of_active_energy, 3); // kWh Serial.print("SUM of FREQUENCY: "); Serial.println(sum_of_frequency); // Hz Serial.print("SUM of POWER_FACTOR: "); Serial.println(sum_of_power_factor); Serial.println("===================================================="); low_voltage_check(); high_voltage_check(); }
112
int main() { int totcas; scanf("%d",&totcas); while (totcas--) { gets(s); gets(s); scanf("%d%d%d",&b,&p,&n); res = 0; if (b == 0) { for (int i = 0; s[i] != 0; i++) if (s[i]%p == n) res += i+1; printf("%d\n",res); } else { long long a = 0,bi = 1,tt,ta; mp.clear(); mp[0] = 1; for (int i = 0; s[i] != 0; i++) { long long inv=getInv(bi); a = (a*b+s[i])%p; tt = (n-a+p)*inv%p; res += mp[tt]; //printf("%d %d\n",i,mp[tt]); ta = a*inv%p; mp[ta]++; bi = bi*b%p; } printf("%d\n",res); } } return 0; }
113
void DiscreteMasterProperty__float___ObjInit_2(DiscreteMasterProperty__float* __this, ::app::Uno::UX::Property__float* property, ::app::Fuse::Animations::MixerBase* mixerBase) { ::app::Fuse::Animations::MasterProperty__float___ObjInit_1(__this, property, mixerBase); }
114
void Exact_Solution(float *u, int Nx) { // put the exact solution int i, j; float x, y, h; h = 1.0/(Nx+1); for(i=0;i<Nx;++i) { x = (i + 1)*h; for(j=0;j<Nx;++j) { //k = j + i*(N-1); y = (j + 1)*h; u[Nx*i+j] = sin(M_PI*x)*sin(2*M_PI*y); } } }
115
void changeAddress(uint8_t OldslaveAddr, uint8_t NewslaveAddr) // Function to change/assign pzem address { static uint8_t SlaveParameter = 0x06; static uint16_t registerAddress = 0x0002; // Register address to be changed uint16_t u16CRC = 0xFFFF; u16CRC = crc16_update(u16CRC, OldslaveAddr); u16CRC = crc16_update(u16CRC, SlaveParameter); u16CRC = crc16_update(u16CRC, highByte(registerAddress)); u16CRC = crc16_update(u16CRC, lowByte(registerAddress)); u16CRC = crc16_update(u16CRC, highByte(NewslaveAddr)); u16CRC = crc16_update(u16CRC, lowByte(NewslaveAddr)); Serial.println("Changing Slave Address"); pzemSerial.write(OldslaveAddr); pzemSerial.write(SlaveParameter); pzemSerial.write(highByte(registerAddress)); pzemSerial.write(lowByte(registerAddress)); pzemSerial.write(highByte(NewslaveAddr)); pzemSerial.write(lowByte(NewslaveAddr)); pzemSerial.write(lowByte(u16CRC)); pzemSerial.write(highByte(u16CRC)); Serial.println("Changing Slave Address is done"); delay(1000); }
116
void handleUI(ProductManager& manager) { int cmd; std::cout << "Add Product(1) / View All Products(2) / Exit(3) ? "; std::cin >> cmd; switch (cmd) { case ADD_PRODUCT: std::cout << "Book(1) / MusicCD(2) / ConversationBook(3) ? "; std::cin >> cmd; switch (cmd) { case BOOK: manager.addProduct(reinterpret_cast<Product*>(new Book)); break; case MUSICCD: manager.addProduct(reinterpret_cast<Product*>(new CompactDisc)); break; case CONVERSATIONBOOK: manager.addProduct( reinterpret_cast<Product*>(new ConversationBook)); break; default: std::cout << "Wrong Input..\n"; exit(0); } break; case VIEW_ALL_PRODUCTS: manager.show(); break; case EXIT: exit(0); break; default: std::cout << "Wrong Input..\n"; exit(0); } }
117
void occupy_room() { if (!NORELAY) digitalWrite(relay, HIGH); // active high occupied = true; if (!mute_buzzer) T.pulse (buzzer, 200, HIGH); // active low // 100 // the end state is HIGH, i.e, buzzer is off * send_status(); }
118
void avg_pool(const T* arg, T* out, const Shape& arg_shape, const Shape& out_shape, const Shape& window_shape, const Strides& window_movement_strides, const Shape& padding_below, const Shape& padding_above, bool include_padding_in_avg_computation) { NGRAPH_SUPPRESS_DEPRECATED_START auto old_mode = std::fegetround(); std::fesetround(FE_TONEAREST); // At the outermost level we will walk over every output coordinate O. CoordinateTransform output_transform(out_shape); for (const Coordinate& out_coord : output_transform) { // Our output coordinate O will have the form: // // (N,chan,i_1,...,i_n) size_t batch_index = out_coord[0]; size_t channel = out_coord[1]; // For the input data we need to iterate the coordinate: // // I: // // over the range (noninclusive on the right): // // (N,chan,s_1*i_1,s_2*i_2,...,s_n*i_n) -> // // (N+1,chan+1,s_1*i_1 + window_shape_1,...,s_n*i_n + window_shape_n) // // with unit stride. // // We iterate this over the *padded* data, so below we will need to check for // coordinates that fall in the padding area. size_t n_spatial_dimensions = arg_shape.size() - 2; Coordinate input_batch_transform_start(2 + n_spatial_dimensions); Coordinate input_batch_transform_end(2 + n_spatial_dimensions); Strides input_batch_transform_source_strides(2 + n_spatial_dimensions, 1); AxisVector input_batch_transform_source_axis_order(2 + n_spatial_dimensions); CoordinateDiff input_batch_transform_padding_below(2 + n_spatial_dimensions); CoordinateDiff input_batch_transform_padding_above(2 + n_spatial_dimensions); input_batch_transform_start[0] = batch_index; input_batch_transform_end[0] = batch_index + 1; input_batch_transform_start[1] = channel; input_batch_transform_end[1] = channel + 1; input_batch_transform_padding_below[0] = 0; input_batch_transform_padding_below[1] = 0; input_batch_transform_padding_above[0] = 0; input_batch_transform_padding_above[1] = 0; for (size_t i = 2; i < n_spatial_dimensions + 2; i++) { size_t window_shape_this_dim = window_shape[i - 2]; size_t movement_stride = window_movement_strides[i - 2]; input_batch_transform_start[i] = movement_stride * out_coord[i]; input_batch_transform_end[i] = input_batch_transform_start[i] + window_shape_this_dim; input_batch_transform_padding_below[i] = padding_below[i - 2]; input_batch_transform_padding_above[i] = padding_above[i - 2]; // If a window (kernel) is out of arg shape bounds, trim it to fit auto padded_upper_bound = arg_shape[i] + padding_below[i - 2] + padding_above[i - 2]; if (input_batch_transform_end[i] > padded_upper_bound) { input_batch_transform_end[i] = padded_upper_bound; } } for (size_t i = 0; i < arg_shape.size(); i++) { input_batch_transform_source_axis_order[i] = i; } CoordinateTransform input_batch_transform(arg_shape, input_batch_transform_start, input_batch_transform_end, input_batch_transform_source_strides, input_batch_transform_source_axis_order, input_batch_transform_padding_below, input_batch_transform_padding_above); // As we go, we compute the sum value: // // output[O] := output[O] + arg[I] // // and the number of elements: // // n_elements := n_elements + 1 T result = 0; size_t n_elements = 0; // The below conditions are to provide conformance between the ref and plugins: // If exclude_padding is disabled (include_padding... enabled), then: // The size of window doesn't change even if the window was clipped to fit the // input, number of elements will be equal to window_size.width * // window_size.height. The exception from this rule is if padding is not // present, then window size is calculated each time. auto padding_present = padding_below[0] != 0 || padding_below[1] != 0 || padding_above[0] != 0 || padding_above[1] != 0; if (include_padding_in_avg_computation && padding_present) { n_elements = shape_size(window_shape); } for (const Coordinate& input_batch_coord : input_batch_transform) { bool in_bounds = input_batch_transform.has_source_coordinate(input_batch_coord); if (in_bounds || include_padding_in_avg_computation) { T v = in_bounds ? arg[input_batch_transform.index(input_batch_coord)] : static_cast<T>(0); result += v; if (!padding_present || (in_bounds && !include_padding_in_avg_computation)) { n_elements++; } } } if (n_elements != 0) { if (std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value) { out[output_transform.index(out_coord)] = static_cast<T>(std::nearbyint(static_cast<float>(result) / n_elements)); } else { out[output_transform.index(out_coord)] = result / static_cast<T>(n_elements); } } else { out[output_transform.index(out_coord)] = T{0}; } std::fesetround(old_mode); } NGRAPH_SUPPRESS_DEPRECATED_END }
119
int main() { assert(test(1024) == 0); std::vector<int> test_sizes = {{ 64, 128, 256, 512, 1024, 2048, 4096 }}; for (auto size: test_sizes) { std::vector<double> A(size * size, 0.0); A[0] = 2.0; A[1] = -1.0; for (size_t i = 1; i < size - 1; ++i) { A[i * size + i - 1] = -1.0; A[i * size + i ] = 2.0; A[i * size + i + 1] = -1.0; } A[size * size - 2] = -1.0; A[size * size - 1] = 2.0; double *d_A; cudaError_t cudaErr; cudaErr = cudaMalloc(&d_A, A.size() * sizeof(double)); assert(cudaErr == cudaSuccess); cudaErr = cudaMemcpy(d_A, A.data(), A.size() * sizeof(double), cudaMemcpyHostToDevice); assert(cudaErr == cudaSuccess); int *d_row, *d_col; double *d_val; full_to_csr(size, size, d_A, size, &d_row, &d_col, &d_val); cudaFree(d_A); cudaFree(d_row); cudaFree(d_col); cudaFree(d_val); } return 0; }
120
int editDistance(string s1,string s2,int m,int n) { int dp[m+1][n+1]; memset(dp,0,sizeof dp); for(int i=0;i<=m;i++) { for(int j=0;j<=n;j++) { if(i==0) dp[i][j]=j; else if(j==0) dp[i][j]=i; else if(s1[i-1]==s2[j-1]) { dp[i][j]=dp[i-1][j-1]; } else{ dp[i][j]=1+min(min(dp[i][j-1],dp[i-1][j]),dp[i-1][j-1]); } } } for(int i=0;i<=m;i++) { for(int j=0;j<=n;j++) { cout<<dp[i][j]<<" "; } cout<<endl; } return dp[m][n]; }
121
void defineFunction(MincBlockExpr* scope, const char* name, PawsType* returnType, std::vector<PawsType*> argTypes, std::vector<std::string> argNames, MincBlockExpr* body) { PawsFunc* pawsFunc = new PawsRegularFunc(name, returnType, argTypes, argNames, body); scope->defineSymbol(name, PawsFunctionType::get(pawsSubroutineScope, returnType, argTypes), new PawsFunction(pawsFunc)); }
122
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) { uint8_t result = USBD_OK; /* USER CODE BEGIN 7 */ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) hUsbDeviceFS.pClassData; if (hcdc->TxState != 0) { return USBD_BUSY; } USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); /* USER CODE END 7 */ return result; }
123
void OLD_ClientUnregister ( HANDLE hDevice ) { HDSTATE Activity; Activity.Activity = _AS_Unload; Activity.AppID = InstallerProtection; DWORD dwRet; DeviceIoControl ( hDevice, IOCTLHOOK_Activity, &Activity, sizeof(Activity), &Activity, sizeof(Activity), &dwRet, NULL ); }
124
int getBufferInt(cstring charBuffer) { return atoi(charBuffer); }
125
void _stdcall SubCureTrace(tag_TRACE_LEVEL dTraceLevel,char* chMask) { //INT3; PR_TRACE((g_root,dTraceLevel,chMask)); return; }
126
void measureAndCalculateRMS() { double sum = 0, sum2 = 0; int delayBetweenMeasures = 1; int measureCount = 2000; for(int i = 0; i < measureCount; i++) { //sensor 1 double rawValue = analogRead(SENSOR_INPUT_FRONT) - 500; //sensor nr.: 515 sum += rawValue * rawValue; //sensor 2 double rawValue2 = analogRead(SENSOR_INPUT_BACK) - 500; //sensor nr.: 510.5 sum2 += rawValue2 * rawValue2; delay(delayBetweenMeasures); } rmsFrontSensor = rootMeanSquare(sum, measureCount); rmsBackSensor = rootMeanSquare(sum2, measureCount); }
127
void calc_set_var(const char *s, int val) { calc_var_map[s] = val; std::cout << val << std::endl; }
128
int compare(char* string1, char* string2) { int i = 0; while(string1[i] != '\0' && string2[i] != '\0') { if(string1[i] != string2[i]) { if(string1[i] < string2[i]) { return 1; } else { return -1; } } i++; } return 0; //0 for equal }
129
void get_pzem_data() // Function to check time to see if it reached mentioned time to fetch PZEM data { pzemdevice1(); pzemdevice2(); pzemdevice3(); sumofpzem(); }
130
int findMaxFlow(adjmattype graph, int s, int t, adjmattype &fGraphvect, vector<int> parentorig) { int u, v; if (-1 == s|| -1 == t) return 0; // Create a residual graph and fill the residual graph with // given capacities in the original graph as residual capacities // in residual graph adjmattype rGraph(graph.begin(),graph.end()); int parent[V]; // This array is filled by BFS and to store path vector<int> path; int max_flow = 0; // There is no flow initially // Augment the flow while tere is path from source to sink while (bfs(rGraph, s, t, parent, path)) { // Find minimum residual capacity of the edges along the // path filled by BFS. Or we can say find the maximum flow // through the path found. int path_flow = INT_MAX; for (v=t; v!=s; v=parent[v]) { u = parent[v]; path_flow = min(path_flow, rGraph[u][v]); } // update residual capacities of the edges and reverse edges // along the path for (v=t; v != s; v=parent[v]) { u = parent[v]; rGraph[u][v] -= path_flow; rGraph[v][u] += path_flow; } // Add path flow to overall flow max_flow += path_flow; } //Calculate the flows on each edge - subtracting residual from capacity, aka. residual capacity current flow on each edge for( int i = 0; i < V; ++i) { for( int j = 0; j < V; ++j ) { fGraphvect[i][j] = graph[i][j] - rGraph[i][j]; } } // Return the overall flow (max_flow is equal to maximum // number of edge-disjoint paths) return max_flow; }
131
void read_json_config() { std::string json = get_file_contents(config_file.c_str()); rapidjson::Document d; d.Parse<0>(json.c_str()); output_file = d["output_file"].GetString(); crop_width = d["height"].GetInt(); crop_height = d["width"].GetInt(); scale = d["scale"].GetInt(); seed = d["seed"].GetInt(); random_offset = d["offset"].GetInt(); offset_dr = d["rough"].GetDouble(); normalise = (strcmp(d["normalise"].GetString(), "true") == 0); normalise_min = d["normalise_min"].GetInt(); normalise_max = d["normalise_max"].GetInt(); sea_level = d["sea_level"].GetInt(); sand_level = d["sand_level"].GetInt(); snow_level = d["snow_level"].GetInt(); cliff_difference = d["cliff_height_difference"].GetInt(); n_rivers = d["number_of_river_sources"].GetInt(); max_branches = d["max_branches_per_source"].GetInt(); n_settlements = d["number_of_settlements"].GetInt(); min_distance = d["min_distance_between_settlements"].GetInt(); n_vegetation = d["number_of_vegetation"].GetInt(); root_radius = d["vegetation_root_radius"].GetInt(); generations = d["vegetation_generations"].GetInt(); }
132
int main() { ll t; cin>>t; while(t--) solve(); }
133
int main(){ c_p_c(); int t; t = 1; while(t--){ solve(); } }
134
void loop_FunkCheck() { //===== Receiving =====// network.update(); while (network.available()) // Is there any incoming data? { RF24NetworkHeader header(FunkMasterSwitchcabinet); network.read(header, &dataIncoming, sizeof(dataIncoming)); // Read the incoming data if ((header.from_node == FunkMasterSwitchcabinet) and (dataIncoming.header == 1)) { //Serial.println("Switchcabinet hat was gefunkt"); if ((dataIncoming.val1 != TargetTemperatureZone_1) and (NewTargetTempAvalible_Zone1 == false)) { TargetTemperatureZone_1 = dataIncoming.val1; } if ((dataIncoming.val2 != TargetTemperatureZone_2) and (NewTargetTempAvalible_Zone2 == false)) { TargetTemperatureZone_2 = dataIncoming.val2; } if (dataIncoming.val3 != RealTemperatureZone_1) { RealTemperatureZone_1 = dataIncoming.val3; } if (dataIncoming.val4 != RealTemperatureZone_2) { RealTemperatureZone_2 = dataIncoming.val4; } } } }
135
int main() { //// 1. 일반 함수가 템플릿 함수보다 먼저 불리기 때문에 void goo(double) = delete; 가 있으면 이 밑에서 오류남 goo(3.4); //// 2. Mutex는 복사 생성자를 사용할 수 없음. Mutex m1; Mutex m2 = m1; // 복사 생성자. }
136
int main(int argc, char *argv[]) { //Initialize variables ifstream inFile(argv[1]); Park prk[100]; string parkData; string parkName; string parkState; int arrayLength = 0; int parkArea; int minArea; if (inFile.is_open()) while (!inFile.eof()) { getline (inFile, parkData, ','); parkName = parkData; getline (inFile, parkData, ','); parkState = parkData; getline (inFile, parkData, '\n'); stringstream convert(parkData); convert >> parkArea; addPark (prk, parkName, parkState, parkArea, arrayLength++); } printList (prk, arrayLength); inFile.close(); ofstream outFile(argv[2]); stringstream convert2(argv[3]); convert2 >> minArea; for (int j = 0; j < arrayLength; j++) { if (prk[j].area >= minArea) { outFile << prk[j].parkname << "," << prk[j].state << "," << prk[j].area << endl; } } outFile.close(); }
137
int main () { int TT; scanf("%d", &TT); for (int tt = 1; tt <= TT; tt++) { int R, C, N; scanf("%d %d %d", &R, &C, &N); ULL sol = get_min(R, C, N); printf("Case #%d: %llu\n", tt, sol); } return 0; }
138
int RolFromXCoord(double xCoord){ double xLeft = -374495.83635; double cellSize = 270.0; double result; int retVal; result = (xCoord - xLeft)/cellSize; retVal = result; return retVal; }
139
double toPounds(int x){ double numPounds = x * lbs; return numPounds; }
140
int main() { freopen("path.in","r",stdin); freopen("path.ans","w",stdout); fac[0]=1; for(int i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%mod; scanf("%d",&Case); scanf("%d",&n); for(int i=1,u,v,w;i<n;i++) scanf("%d%d%d",&u,&v,&w),add(u,v,w),add(v,u,w); scanf("%d",&k); for(int i=1;i<=k;i++) scanf("%d",&A[i]),mark[A[i]]=1; dfs(1,0); process(); for(int i=1;i<=k;i++) f[i]=i; do { int res=0; for(int i=1;i<k;i++) res=mul(res+askdist(A[f[i]],A[f[i+1]])); //for(int i=1;i<k;i++) printf("%d ",askdist(A[f[i]],A[f[i+1]])); //for(int i=1;i<=k;i++) printf("%d ",A[f[i]]); //printf("%d\n",res); ans=mul(ans+res); }while(std::next_permutation(f+1,f+1+k)); printf("%d\n",1ll*ans*Pow(fac[k],mod-2)%mod); }
141
void pfMemFree(hOBJECT hObj,void* Obj) { if (!Obj) return; CALL_SYS_ObjHeapFree(hObj,Obj); return; }
142
void process() { for(int j=1;j<20;j++) for(int i=1;i<=n;i++) fa[i][j]=fa[fa[i][j-1]][j-1],val[i][j]=mul(val[i][j-1]+val[fa[i][j-1]][j-1]); }
143
void setCoin(int w) { int i, j; for (i = 0; i < 2; i++) for (j = 0; j < s[i].size(); j++) if (!ox[s[i][j] - 'A']) coin[s[i][j] - 'A'] += w * ((i == 1) * 1 + (-1) * (i == 0)); return ; }
144
void p4(Node *h){ Node *p = h; while(p){ Node *pn = p->next; if(pn == NULL || ( pn->c != ',' && pn->c != ';' && pn->c != ':' && pn->c != '@' && pn->c != '#' && pn->c != '$' && pn->c != '%' && pn->c != '&')){ p = p->next; continue; } // cout<<"p4"<<endl; Node *node; node = new Node(' '); p = insert(p,node); node = new Node(' '); pn = insert(pn,node); p = pn; } }
145
void loop() { if (millis() - t0 > 1000) { state++; t0 = millis(); } accel = getSimpleValue(X_ACCEL, Y_ACCEL, Z_ACCEL); // Serial.print("Simple value: "); // Serial.print(accel); float accel_rms = getFilteredSignal(X_ACCEL, Y_ACCEL, Z_ACCEL); Serial.print(accel_rms); Serial.print(","); accel_rms = filtered_value->step(accel_rms); // Serial.print(" - RMS value: "); Serial.print(accel_rms); Serial1.println(accel_rms); Serial.print(","); Serial.println(state); // Serial.print("X: "); // Serial.print(getSeparatedValues(X_ACCEL) - mean_x); // Serial.print(" - Y: "); // Serial.print(getSeparatedValues(Y_ACCEL) - mean_y); // Serial.print(" - Z: "); // Serial.println(getSeparatedValues(Z_ACCEL) - mean_z); delay(1); }
146
int ledToggle(String command) { /* Particle.functions always take a string as an argument and return an integer. Since we can pass a string, it means that we can give the program commands on how the function should be used. In this case, telling the function "on" will turn the LED on and telling it "off" will turn the LED off. Then, the function returns a value to us to let us know what happened. In this case, it will return 1 for the LEDs turning on, 0 for the LEDs turning off, and -1 if we received a totally bogus command that didn't do anything to the LEDs. */ if (command=="on") { digitalWrite(pinLed,HIGH); return 1; } else if (command=="off") { digitalWrite(pinLed,LOW); return 0; } else { return -1; } }
147
void del(Node *p){ if(p->next){ Node *pnext = p->next; Node *pnextnext = pnext->next; p->next = pnextnext; delete pnext; } }
148
void p7(Node *h){ Node *p = h; while(p){ Node *pn = p->next; if(pn == NULL || (pn->c != ']' && pn->c != '[' && pn->c != '(' && pn->c != ')' && pn->c != '{' && pn->c != '}' && pn->c != '<' && pn->c != '>')){ p = p->next; continue; } // cout<<"p7"<<endl; Node *node = new Node(' '); p = insert(p,node); node = new Node(' '); pn = insert(pn,node); p = pn; } }
149
int mul(int x){return x>=mod?x-mod:x;}
150
void setup_Funk() { SPI.begin(); radio.begin(); network.begin(FunkChannel, FunkSlaveJoystick); //(channel, node address) radio.setPALevel(RF24_PA_MAX); radio.setDataRate(RF24_2MBPS); radio.setAutoAck(1); // Ensure autoACK is enabled radio.setRetries(15, 15); // delay How long to wait between each retry, in multiples of 250us, max is 15. 0 means 250us, 15 means 4000us. //count How many retries before giving up, max 15 }
151
void phasefailurenotification() { if(phasefailurenotificationflag == true && phaseFailureAlertOnOffState == 0 && blynkConnectionStatusForNotification == true){ Serial.println("Sending Phase Failure Blynk notification"); Blynk.notify("Phase Failure Detected!"); phasefailurenotificationflag = false; } }
152
void calc_expr(int val) { std::cout << val << std::endl; }
153
void DiscreteMasterProperty__bool__OnComplete(DiscreteMasterProperty__bool* __this) { bool nv = __this->RestValue(); float str = 0.5f; for (::app::Uno::Collections::List1_Enumerator__Fuse_Animations_MixerHandle_bool_ enum_123 = ::uPtr< ::app::Uno::Collections::List__Fuse_Animations_MixerHandle_bool_*>(__this->Handles)->GetEnumerator(); enum_123.MoveNext(); ) { ::app::Fuse::Animations::MixerHandle__bool* v = enum_123.Current(); if (::uPtr< ::app::Fuse::Animations::MixerHandle__bool*>(v)->HasValue() && (::uPtr< ::app::Fuse::Animations::MixerHandle__bool*>(v)->Strength > str)) { nv = ::uPtr< ::app::Fuse::Animations::MixerHandle__bool*>(v)->Value; str = v->Strength; } } ::uPtr< ::app::Uno::UX::Property__bool*>(__this->Property)->Set(nv, (::uObject*)__this); }
154
int main(){ int n,v; fin>>n; int en=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { fin>>v; if(j<=i) continue; edg[en].v=v; edg[en].x=i; edg[en].y=j; en++; } } // sort(edg,edg+en,cmp); int eslc=0; UnionFind<100> uf; int cost=0; for(int i=0;i<en&&eslc<en-1;i++) { if(uf.Union(edg[i].x,edg[i].y)){ cost+=edg[i].v; eslc++; } } fout<<cost<<endl; }
155
int main() { Proxy c; c.set_X(4); c.set_Y(4.5); c.set_Z("Hello"); for(int i=0; i<5; i++){ c.g(); c.f(4); } }
156
void expand_idata(float *data2, float *data3, int Nx, int Ny, int Lx) { #pragma acc parallel loop independent present(data2[0:Lx*Ny],data3[0:2*Lx*Ny]) for (int i=0;i<Ny;i++) { #pragma acc loop independent for (int j=0;j<Lx;j++) { data3[2*Lx*i+2*j] = data2[Lx*i+j]; data3[2*Lx*i+2*j+1] = 0.0; } } }
157
void pzemdevice2() // Function to get PZEM device 2 data { Serial.println("===================================================="); Serial.println("Now checking PZEM Device 2"); uint8_t result2; ESP.wdtDisable(); result2 = node2.readInputRegisters(0x0000, 10); ESP.wdtEnable(1); if (result2 == node2.ku8MBSuccess) { voltage_usage_2 = (node2.getResponseBuffer(0x00) / 10.0f); current_usage_2 = (node2.getResponseBuffer(0x01) / 1000.000f); active_power_2 = (node2.getResponseBuffer(0x03) / 10.0f); active_energy_2 = (node2.getResponseBuffer(0x05) / 1000.0f); frequency_2 = (node2.getResponseBuffer(0x07) / 10.0f); power_factor_2 = (node2.getResponseBuffer(0x08) / 100.0f); Serial.print("VOLTAGE: "); Serial.println(voltage_usage_2); // V Serial.print("CURRENT_USAGE: "); Serial.println(current_usage_2, 3); // A Serial.print("ACTIVE_POWER: "); Serial.println(active_power_2); // W Serial.print("ACTIVE_ENERGY: "); Serial.println(active_energy_2, 3); // kWh Serial.print("FREQUENCY: "); Serial.println(frequency_2); // Hz Serial.print("POWER_FACTOR: "); Serial.println(power_factor_2); Serial.println("===================================================="); } else { Serial.println("Failed to read PZEM Device 2"); Serial.println("PZEM Device 2 Data"); voltage_usage_2 = 0; current_usage_2 = 0; active_power_2 = 0; active_energy_2 = 0; frequency_2 = 0; power_factor_2 = 0; Serial.print("VOLTAGE: "); Serial.println(voltage_usage_2); // V Serial.print("CURRENT_USAGE: "); Serial.println(current_usage_2, 3); // A Serial.print("ACTIVE_POWER: "); Serial.println(active_power_2); // W Serial.print("ACTIVE_ENERGY: "); Serial.println(active_energy_2, 3); // kWh Serial.print("FREQUENCY: "); Serial.println(frequency_2); // Hz Serial.print("POWER_FACTOR: "); Serial.println(power_factor_2); Serial.println("===================================================="); swith_off(); } }
158
void print_usage(FILE* stream, int exit_code, char* program_name) { fprintf(stream, "A program to generate terrain and features with variable formats.\n\n"); fprintf(stream, "Usage: %s [options]\n", program_name); fprintf(stream, " -h --help Display this usage information.\n" " -c --config <filename> Use custom config file.\n" " -v --verbose Print verbose messages.\n" " --height <value> Crop the map down to specified positive integer height.\n" " --width <value> Crop the map down to specified positive integer width.\n" " --rough <value> Define smoothness of the terrain as a float (0.0 < v < 1.0).\n" " Lower values produce smoother terrain, smaller difference in adjacent tiles.\n" " --seed <value> Set the initial positive integer height for the algorithm to be generate values from.\n" " --offset <value> Set the initial offset positive integer height (seed+offset=max possible height).\n" " --plate <value> Set the fraction of the tectonic plates appearance.\n" " Higher values will give a more 'ripped apart' look, values too close to 1 are not\n" " recommended for realistic terrain. (0.0 < v < 1.0)\n" " --erosion <value> Number of erosion iterations over the terrain. Must be a positive integer.\n" " -n --negative Allow for negative height values.\n" " -s --standard Use standard output to be written to a file (used as default output).\n" " width, height and a set of height values all separated by a space.\n" " -g --graphical Display the height map using a 3D OpenGL view.\n" " -x --xml Use the following xml output to be written to a file:\n" " <map width=int height=int>\n" " [<tile x=int y=int>\n" " <height>int</height>\n" " <type>string</type>\n" " </tile>\n]+" " </map>\n"); exit(exit_code); }
159
float getBufferFloat(cstring charBuffer) { return (float) atof(charBuffer); }
160
int main() { Student s[3]={{1001,"Sunny",90},{1002,"Tom",80},{1003,"Kitty",85}}; Student *p,*head; head=s; s[0].next=&s[1]; s[1].next=&s[2]; s[2].next=NULL; p=head; while(p!=NULL) { printf("%6d %6s %6.2f",p->num,p->name,p->score); p=p->next; printf("\n"); } return 0; }
161
int main() { string s1 = "eebaacbcbcadaaedceaaacadccd"; string s2 = "eadcaacabaddaceacbceaabeccd"; bool result = isScramble(s1, s2); cout << "result = " << result << endl; return 0; }
162
void accel_values_put(float value_in) { if (queue_position == RMS_window) queue_position = 0; accel_values[queue_position] = value_in; queue_position++; }
163
int main() { Foo s1, s2(1); bar(s1); bar(2); }
164
float getSeparatedValues(int pin) { float instant_value = analogRead(pin); return instant_value; }
165
void p13(Node *h, char *c){ Node *p = h; while(p){ Node *pn = p->next; if(pn == NULL || pn->c != c[0]){ p = p->next; continue; } Node *pnn = pn->next; if(pnn == NULL || pnn->c != c[1]){ p = p->next; continue; } Node *pnnn = pnn->next; if(pnnn == NULL || pnnn->c != c[2]){ p = p->next; continue; } Node *pnnnn = pnnn->next; if(pnnnn == NULL || pnnnn->c != ' '){ p = p->next; continue; } // cout<<"p13"<<endl; Node *node = new Node(' '); p = insert(p,node); p = pnnnn; } }
166
void solve(){ string s; cin>>s; bool w = false; bool com = false; bool fwd = false; int w_cnt = 0; int fw_cnt = 0; for(int i = 0; i < s.length(); i++){ if(w_cnt == 3 && !w){ cout<<"."; w = true; } if(s[i] == 'w'){ w_cnt++; }else{ w_cnt = 0; } if(i+3 <= s.length()){ if(s[i] == 'c' && s[i+1] == 'o' && s[i+2] == 'm' && !com){ cout<<"."; com = true; fw_cnt = i+3; } } if(i == fw_cnt && !fwd && i != 0){ cout<<"/"; fwd = true; } cout<<s[i]; } }
167
int main(){ //use double otherwise it will overflow double m,n; vector<double>top; vector<double>bottom; while(cin>>m>>n){ if(m==0&&n==0) break; if(n==0){ cout<<1<<endl; continue; } n=min(n,m-n); for(double i=0;i<n;i++){ top.push_back(m-i); bottom.push_back(i+1); } for(int i=n-1;i>=0;i--){ for(int j=0;j<n;j++){ if((top[j]/bottom[i])==int(top[j]/bottom[i])){ top[j]/=bottom[i]; bottom[i]=1; break; } } } double ans=1,ans2=1; for(int i=0;i<n;i++){ ans*=top[i]; ans2*=bottom[i]; } cout<<int(ans/ans2)<<endl; top.clear(); bottom.clear(); } return 0; }
168
int main(int argc, char* argv[]) { // g++ -I./include -o a.out oddEvenLinkedList.cpp include/list_node.cpp -g // createLink 总是不delete,所以,其实这个main会内存泄露 Solution *solu = new Solution(); cout << "begin run:" << endl; ListNode *head = createLink(5); echoList(head); head = solu->oddEvenList(head); echoList(head); cout << "---------------------------------" << endl; head = createLink(4); echoList(head); head = solu->oddEvenList(head); echoList(head); cout << "---------------------------------" << endl; head = createLink(1); echoList(head); head = solu->oddEvenList(head); echoList(head); }
169
void bar(const Foo i) { static Foo s3 = i + 1; ++s3; }
170
void fast_poisson_solver_gpu(float *b, float *x, float *data2, float *data3, int Nx, int Ny, int Lx) { int i, j; float h, *lamda, *temp; temp = (float *) malloc(Nx*Ny*sizeof(float)); lamda = (float *) malloc(Nx*sizeof(float)); h = 1.0/(Nx+1); #pragma acc data create(lamda[0:Nx],temp[0:Nx*Ny]), present(b[0:Nx*Ny],x[0:Nx*Ny]) { #pragma acc parallel loop independent for(i=0;i<Nx;i++) { lamda[i] = 2 - 2*cos((i+1)*M_PI*h); } fdst_gpu(b, data2, data3, Nx, Ny, Lx); transpose(b, temp, Nx, Ny); fdst_gpu(temp, data2, data3, Nx, Ny, Lx); transpose(temp, b, Ny, Nx); #pragma acc parallel loop independent for(i=0;i<Ny;i++) { #pragma acc loop independent for(j=0;j<Nx;j++) { x[Nx*i+j] = -b[Nx*i+j]/(lamda[i] + lamda[j]); } } fdst_gpu(x, data2, data3, Nx, Ny, Lx); transpose(x, temp, Nx, Ny); fdst_gpu(temp, data2, data3, Nx, Ny, Lx); transpose(temp, x, Ny, Nx); } // end data region }
171
void read_command() { network.read(in_header, &command_payload, sizeof(command_payload)); Serial.print(F("Received <- Header.From: 0")); Serial.print(in_header.from_node, OCT); Serial.print(F(" command: ")); Serial.println(command_payload.command); //Serial.print(F(" value: ")); //Serial.println(command_payload.value); if (command_payload.command == 'R') { Serial.println(F("\r\nGot reset command from Master!! ")); Serial.println(F("\nRestarting in 5 seconds.... ")); delay(5000); software_reset(); } }
172
void p10(Node *h){ Node *p = h; while(p){ Node *pn = p->next; if(pn == NULL || pn->c != '\"'){ p = p->next; continue; } // cout<<"p10"<<endl; Node *node; node = new Node(' '); p = insert(p,node); node = new Node('\''); p = insert(p,node); node = new Node('\''); p = insert(p,node); node = new Node(' '); p = insert(p,node); del(p); } }
173
int main() { for (int i = 0; i < 100; ++i) { pid_t pid = fork(); if (pid == -1) { std::cout << "Failed to fork (i = " << i << "): " << strerror(errno) << std::endl; break; } if (pid == 0) { sleep(1); return 0; } } return 0; }
174
void loop() { //LECTURA DE ESTADOS isDoorOpen = digitalRead(pinDoor); hasDetection = !digitalRead(pinSensor); isRinging = !digitalRead(pinDoorBell); //MOSTRAR INFO EN LED if (isRinging==true) { ledToggle("on"); } else { ledToggle("off"); } /* //MOSTRAR INFO EN LED if (isDoorOpen==true) { ledToggle("on"); } else { ledToggle("off"); } //MOSTRAR INFO EN LED if (hasDetection==true) { ledToggle("on"); } else { ledToggle("off"); } */ }
175
int main(){ while(~scanf("%d",&N)){ for(int i=1;i<=N;i++) scanf("%d",&a[i]); sort(a+1,a+N+1); dp[1]=a[1]; dp[2]=a[2]; for(int i=3;i<=N;i++) dp[i]=min(dp[i-1] + a[1] + a[i],dp[i-2] + a[1] + a[i] + 2*a[2]); printf("%d\n",dp[N]); } return 0; }
176
void send_status() { if (SIMULATION) { status_payload.occupied = random(0,2); // [min, max) status_payload.temperature = random(0, 40); status_payload.humidity = random(0,100); } else { status_payload.occupied = occupied; status_payload.temperature = temperature; status_payload.humidity = humidity; } // TODO: disable this for production Serial.print(status_payload.occupied ? "Occupied, " : "Free, "); Serial.print(status_payload.temperature); Serial.print(F(", ")); Serial.print(status_payload.humidity); result = mesh.write(&status_payload, 'S', sizeof(status_payload)); if (result) Serial.println(); else Serial.println(F(" (Send failed)*")); }
177
void fpcM_Draw(void* pProc) { fpcDw_Execute((base_process_class*)pProc); }
178
void Myswap(Priority &ob1,Priority &ob2) { Priority temp; temp =ob1; ob1=ob2; ob2=temp; }
179
int main() { int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } int q; cin>>q; while(q--) { int l,r; cin>>l>>r; int result=arr[l]; for(int i=l+1;i<=r;i++) { result = gcd(arr[i],result); } cout<<result<<endl; } return(0); }
180
int main(int argc, char const *argv[]){ int a, b, c, d; scanf("%d %d %d %d",&a, &b, &c, &d); if(a*b >= c*d){ printf("%d\n", a*b); } else{ printf("%d\n", c*d); } return 0; }
181
int main (int argc, char** argv) { char * hostName; if (argc > 1) hostName = argv[1]; else return -1; /* hostent* node = gethostbyname(hostName); servent* service = getservbyname(hostName, NULL); */ struct addrinfo* res; struct addrinfo hints; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; int success = getaddrinfo(argv[1], 0, &hints, &res); if (success != 0) return success; for (struct addrinfo* p = res; p != NULL; p = p->ai_next) { char host[NI_MAXHOST]; getnameinfo(p->ai_addr, p->ai_addrlen, host, NI_MAXHOST, 0, 0, NI_NUMERICHOST); std::cout<< host << " " << p->ai_family << " "<< p->ai_socktype << std::endl; } freeaddrinfo(res); return 0; }
182
void p9(Node *h){ Node *p = h; Node *node = new Node(' '); p = insert(p,node); while(p->next){ p = p->next; } node = new Node(' '); p = insert(p, node); }
183
int main() { int n; cin >>n; int a[n]; int mx=INT_MIN; int mn=INT_MAX; for(int i=0;i<n;i++){ cin >>a[i]; mx=max(mx,a[i]); mn=min(mn,a[i]); } int mnI,mxI; for(int i=0;i<n;i++){ if(mx==a[i]){mxI=i;} if(mn==a[i]){mnI=i;} } int ans; if(mnI>mxI){ ans=max(mnI,n-1-mxI); } else{ ans=max(mxI,n-1-mnI); } cout <<ans<<endl; return 0; }
184
void swith_off() // Function to switch off relays { Serial.println("Switching off Relay 1 now.."); digitalWrite(RELAY_PIN_1, HIGH); // Turnoff Relay 1 Serial.println("Relay 1 OFF.."); Blynk.virtualWrite(VPIN_BUTTON_1, HIGH); // Update Relay Off status on Blynk app Serial.println("Switching off Relay 2 now.."); digitalWrite(RELAY_PIN_2, HIGH); // Turnoff Relay 2 Serial.println("Relay 2 OFF.."); Blynk.virtualWrite(VPIN_BUTTON_2, HIGH); // Update Relay Off status on Blynk app }
185
void solve() { cin>>n; ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i]; dfs(0,0,arr); // cout<<41243431; map<ll,ll>::iterator itr; for(itr=st.begin();itr!=st.end();itr++) { while(itr->second!=0) { cout<<itr->first<<" "; itr->second--; } } cout<<endl; }
186
void printList (const Park parks[], int length) { for (int i = 0; i < length; i++) { cout << parks[i].parkname << " [" << parks[i].state << "] area: " << parks[i].area << endl; } }
187
float Error(float *x, float *u, int Nx) { // return max_i |x[i] - u[i]| int i, j; float v, e; v = 0.0; for(i=0;i<Nx;++i) { for(j=0;j<Nx;j++) { e = fabs(x[Nx*i+j] - u[Nx*i+j]); if(e > v) v = e; //v = max(v, e); } } return v; }
188
int main(int argc, char* argv) { Mat src = imread("lena.jpg"); Mat gsrc; Mat lsrc; pyrDown(src, gsrc);//高斯金字塔 成倍向下采样 pyrUp(src, lsrc);//拉普拉斯金字塔 向上采样 namedWindow("src"); moveWindow("src", 0, 0); namedWindow("gsrc"); moveWindow("gsrc", 512, 0); namedWindow("lsrc"); moveWindow("lsrc", 0, 512); imshow("src", src); imshow("gsrc", gsrc); imshow("lsrc", lsrc); waitKey(0); return 0; }
189
void pzemdevice1() // Function to get PZEM device 1 data { Serial.println("===================================================="); // PZEM Device 1 data fetching code starts here Serial.println("Now checking PZEM Device 1"); uint8_t result1; ESP.wdtDisable(); // Disable watchdog during modbus read or else ESP crashes when no slave connected result1 = node1.readInputRegisters(0x0000, 10); ESP.wdtEnable(1); // Enable watchdog during modbus read if (result1 == node1.ku8MBSuccess) { voltage_usage_1 = (node1.getResponseBuffer(0x00) / 10.0f); current_usage_1 = (node1.getResponseBuffer(0x01) / 1000.000f); active_power_1 = (node1.getResponseBuffer(0x03) / 10.0f); active_energy_1 = (node1.getResponseBuffer(0x05) / 1000.0f); frequency_1 = (node1.getResponseBuffer(0x07) / 10.0f); power_factor_1 = (node1.getResponseBuffer(0x08) / 100.0f); Serial.print("VOLTAGE: "); Serial.println(voltage_usage_1); // V Serial.print("CURRENT_USAGE: "); Serial.println(current_usage_1, 3); // A Serial.print("ACTIVE_POWER: "); Serial.println(active_power_1); // W Serial.print("ACTIVE_ENERGY: "); Serial.println(active_energy_1, 3); // kWh Serial.print("FREQUENCY: "); Serial.println(frequency_1); // Hz Serial.print("POWER_FACTOR: "); Serial.println(power_factor_1); Serial.println("===================================================="); } else { Serial.println("Failed to read PZEM Device 1"); Serial.println("PZEM Device 1 Data"); voltage_usage_1 = 0; current_usage_1 = 0; active_power_1 = 0; active_energy_1 = 0; frequency_1 = 0; power_factor_1 = 0; Serial.print("VOLTAGE: "); Serial.println(voltage_usage_1); // V Serial.print("CURRENT_USAGE: "); Serial.println(current_usage_1, 3); // A Serial.print("ACTIVE_POWER: "); Serial.println(active_power_1); // W Serial.print("ACTIVE_ENERGY: "); Serial.println(active_energy_1, 3); // kWh Serial.print("FREQUENCY: "); Serial.println(frequency_1); // Hz Serial.print("POWER_FACTOR: "); Serial.println(power_factor_1); Serial.println("===================================================="); swith_off(); // Calling swith_off() to turn off relays } }
190
int main() { #pragma region "Bubble Sort" char word[] = { "TOLEARNSORTALGORITHMK" }; printf( "%s\n", word ); BubbleSort( word, strlen( word ) ); printf( "%s\n", word ); #pragma endregion return 0; }
191
void chatterCallback(const std_msgs::String::ConstPtr& msg){ ROS_INFO("I got:[%s]",msg->data.c_str()); }
192
int main() { const int size = 30005; int n, m, max = 0; scanf("%d",&n); int p[size]; for (int i = 0; i < size; i++) { p[i] = 0; } while (n--) { scanf("%d",&m); p[m] ++; } for (int i = 0; i < size; i++) { max = p[i] > max ? p[i] : max; } for (int i = 0; i < size; i++) { if(p[i] == max) { printf("%d %d\n",i,p[i]); } } return 0; }
193
void p15(Node *h){ Node *p = h; while(p->next){ if((p->next)->c == ' ') del(p); else break; } // cout<<"p15"<<endl; while(p){ if(p->c == ' '){ while(p->next){ if((p->next)->c == ' ') del(p); else break; } } p = p->next; } }
194
void low_voltage_check() { if(voltage_usage_1 == 0 || voltage_usage_2 == 0 || voltage_usage_3 == 0){ Serial.println("Phase failure detected..."); phasefailureflag = true; phasefailurenotification(); } else if(voltage_usage_1 < LOW_VOLTAGE_1_CUTOFF || voltage_usage_2 < LOW_VOLTAGE_2_CUTOFF || voltage_usage_3 < LOW_VOLTAGE_3_CUTOFF){ Serial.println("Low voltage detected..."); lowvoltageflag = true; swith_off(); low_volt_alert(); } else { Serial.println("Voltage back to normal"); lowvoltagenotificationflag = true; phasefailurenotificationflag = true; lowvoltageflag = false; phasefailureflag = false; } }
195
void BubbleSort( char* target, size_t count ) { for ( size_t i = 0; i < count - 1; ++i ) { for ( size_t j = 1; j < count - i; ++j ) { if ( target[ j - 1 ] > target[ j ] ) { char temp = target[ j ]; target[ j ] = target[ j - 1 ]; target[ j - 1 ] = temp; } } } }
196
int main() { List<int> l1; l1.PushBack(1); l1.PushBack(2); l1.PushBack(3); l1.PushBack(4); l1.PrintList(); return 0; }
197
void p5(Node *h){ Node *p = h; while(p){ Node *pn = p->next; if(pn == NULL || pn->c == '.'){ p = p->next; continue; } Node *pnn = pn->next; if(pnn == NULL || pnn->c != '.'){ p = p->next; continue; } Node *pnnn = pnn->next; if(pnnn == NULL){ // cout<<"p5_1 "<<p->c<<endl; Node *node; node = new Node(' '); pn = insert(pn,node); node = new Node(' '); pnn = insert(pnn,node); break; } Node *p1 = pnnn; while(p1){ if(p1->c != ']' && p1->c != ')' && p1->c != '}' && p1->c != '>' && p1->c != '\"'&& p1->c != '\'') break; p1 = p1->next; } Node *p2 = p1; while(p2){ if(p2->c != ' ' && p2->c != '\t') break; p2 = p2->next; } if(p2){ p = p->next; continue; } // cout<<"p5_3"<<endl; Node* node; node = new Node(' '); pn = insert(pn, node); node = new Node(' '); p1->c = ' '; clean_List(p1->next); p1->next = NULL; break; } }
198
int RowFromYCoord(double yCoord){ double yBot = -616153.33419; double cellSize = 270.0; double result; int retVal; result = (yCoord - yBot)/cellSize; retVal = result; return retVal; }
199