int main() { scanf ("%d %ld", &n, &k); int i, j, flag = 1; for (i = 1; i <= n; i++) scanf ("%ld", &A[i]); // init dp for (i = 1; i <= n; i++) { dp[i] = A[i]; if (dp[i] == k) build_answer (i, i); } // 从第二层开始 for (i = 2; i <= n; i++) { int index = 1; for (j = i; j <= n; j++) { dp[index] = dp[index] + A[j]; // printf ("dp[%d][%d] = %ld ", i, index, dp[index]); if (dp[index] == k) { build_answer (index, index + i - 1); flag = 0; } index++; } // printf ("\n"); } if (flag) printf ("No Solution\n"); else printf ("%d %d\n", left, right); return 0; }
void device_full_custom_task(void) #endif { U32 time=0; bool startup=true; #ifdef FREERTOS_USED portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); while (true) { vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DFC_PERIOD); if( startup ) { time+=configTSK_USB_DFC_PERIOD; #define STARTUP_LED_DELAY 100 if ( time== 1*STARTUP_LED_DELAY ) LED_On( LED_MONO0_GREEN ); else if( time== 2*STARTUP_LED_DELAY ) LED_On( LED_MONO1_GREEN ); else if( time== 3*STARTUP_LED_DELAY ) LED_On( LED_MONO2_GREEN ); else if( time== 4*STARTUP_LED_DELAY ) LED_On( LED_MONO3_GREEN ); else if( time== 5*STARTUP_LED_DELAY ) LED_Off( LED_MONO0_GREEN ); else if( time== 6*STARTUP_LED_DELAY ) LED_Off( LED_MONO1_GREEN ); else if( time== 7*STARTUP_LED_DELAY ) LED_Off( LED_MONO2_GREEN ); else if( time== 8*STARTUP_LED_DELAY ) LED_Off( LED_MONO3_GREEN ); else if( time== 9*STARTUP_LED_DELAY ) startup=false; } // First, check the device enumeration state if (!Is_device_enumerated()) continue; #else // First, check the device enumeration state if (!Is_device_enumerated()) return; #endif // FREERTOS_USED if(Is_usb_out_received(EP_FC_OUT)) { U32 nchar; Usb_reset_endpoint_fifo_access(EP_FC_OUT); memset(rxbuf, 0, RXBUF_SIZE); usb_read_ep_rxpacket(EP_FC_OUT, &rxbuf, RXBUF_SIZE, NULL); Usb_ack_out_received_free(EP_FC_OUT); //printf("Received %s\n\r", rxbuf); if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=temp") ) { // Temperature sensor nchar=build_answer(txbuf, "temp"); b_temperature_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=js") ) { // Joystick nchar=build_answer(txbuf, "js"); b_joystick_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb1") ) { // Push button 1 nchar=build_answer(txbuf, "pb1"); b_pushb1_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb2") ) { // Push button 2 nchar=build_answer(txbuf, "pb2"); b_pushb2_get_value( txbuf+nchar ); b_report_pending=true; } #if BOARD == EVK1100 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb3") ) { // Push button 3 nchar=build_answer(txbuf, "pb3"); sprintf( txbuf+nchar, "RELEASE\r\n"); b_report_pending=true; } #endif else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=light") ) { // light U32 value; nchar=build_answer(txbuf, "light"); b_light_get_value( txbuf+nchar, &value ); e_ledm_refresh_intensity( value ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm1") ) { // led1 nchar=build_answer(txbuf, "ledm1"); b_ledm1_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm2") ) { // led2 nchar=build_answer(txbuf, "ledm2"); b_ledm2_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm3") ) { // led3 nchar=build_answer(txbuf, "ledm3"); b_ledm3_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm4") ) { // led4 nchar=build_answer(txbuf, "ledm4"); b_ledm4_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strncmp((const char*)rxbuf, STR_SET_LEDM1, strlen(STR_SET_LEDM1)) ) { // led1 nchar=build_answer(txbuf, "ledm1"); e_ledm1_set_value(rxbuf+strlen(STR_SET_LEDM1), txbuf+nchar); b_report_pending=true; } else if( !strncmp((const char*)rxbuf, STR_SET_LEDM2, strlen(STR_SET_LEDM2)) ) { // led2 nchar=build_answer(txbuf, "ledm2"); e_ledm2_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar); b_report_pending=true; } else if( !strncmp((const char*)rxbuf, STR_SET_LEDM3, strlen(STR_SET_LEDM3)) ) { // led3 nchar=build_answer(txbuf, "ledm3"); e_ledm3_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar); b_report_pending=true; } else if( !strncmp((const char*)rxbuf, STR_SET_LEDM4, strlen(STR_SET_LEDM4)) ) { // led4 nchar=build_answer(txbuf, "ledm4"); e_ledm4_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=accx") ) { // accelerometer nchar=build_answer(txbuf, "accx"); accelerometer_measure(0, txbuf+nchar); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=accy") ) { // accelerometer nchar=build_answer(txbuf, "accy"); accelerometer_measure(1, txbuf+nchar); b_report_pending=true; } } if( b_report_pending && Is_usb_in_ready(EP_FC_IN) ) { U8 data_to_transfer; char* ptr_cram=txbuf; //printf( "Sending %s", txbuf); #if 0 Usb_reset_endpoint_fifo_access(EP_FC_IN); usb_write_ep_txpacket(EP_FC_IN, &txbuf, TXBUF_SIZE, NULL); Usb_ack_in_ready_send(EP_FC_IN); #endif data_to_transfer = strlen(txbuf); while (data_to_transfer) { while (!Is_usb_in_ready(EP_FC_IN)); Usb_reset_endpoint_fifo_access(EP_FC_IN); data_to_transfer = usb_write_ep_txpacket(EP_FC_IN, ptr_cram, data_to_transfer, (const void**)&ptr_cram); Usb_ack_in_ready_send(EP_FC_IN); } b_report_pending=false; } #ifdef FREERTOS_USED } #endif }