408 2016 43

该文提出了一种基于快速排序思想的集合划分算法,旨在找到一个正整数集合的两种划分方式,使得两子集的元素数量差最小且元素和的差值最大。算法首先进行一次部分排序,然后根据中间值将集合分为两部分。平均时间复杂度和空间复杂度与快速排序类似。
/*43. (15 分)已知由η (n≥2)个正整数构成的集合A= {ax}0≤k<n},将其划分为两个
不相交的子集A1和A2,元素个数分别是n1和n2,A1和A2中元素之和分别为S1和S2。设
计一个尽可能高效的划分算法,满足|n1-n2|最小且|S1-S2|最大。要求:
(1)给出算法的基本设计思想。
(2)根据设计思想,采用C或C+ +语言描述算法,关键之处给出注释。
(3)说明你所设计算法的平均时间复杂度和空间复杂度。
*/
#include <stdio.h>

//参照快速排序的思想
int setPartition(int *a,int len){
    int high=len-1;
    int low=0;
    int pivot=0;
    int high0=high;//保存上次low和high的位置
    int low0=low;
    while(true){
        pivot=a[low];
        while(low<high){

            while (a[high]>=pivot&&low<high){
                high--;
            }
            a[low]=a[high];
            while (a[low]<=pivot&&low<high){
                low++;
            }
            a[high]=a[low];
        }
        a[low]=pivot;
        if (low==len/2-1){
            break;
        }
        //A1部分元素少于A2部分,则取前半部分继续划分
        if(low<len/2-1){
            low++;
            low0=low;
            high=high0;
        }else{//取后半部分继续划分
            high--;
            high0=high;
            low=low0;
        }
    }
    int S1=0;
    for (int i = 0; i < len/2; ++i) {
        S1+=a[i];
    }
    int S2=0;
    for (int i = len/2; i < len; ++i) {
        S2+=a[i];
    }
    int differences=S2-S1;
    return differences;
}
int main() {
    int A[10]={4,1,12,18,7,13,18,16,5,15};
    int defference=setPartition(A,sizeof A/sizeof A[0]);
    for (int i = 0; i < sizeof A/sizeof A[0]; ++i) {
        printf("%d  ",A[i]);
    }
    printf("\ndifferences=%d",defference);
    return 0;
}

eekBar: drawCircleAndIconInternal, needAnimation:false, upScale: 1.0, icon: TELE, fadeIn: false, fadeOut: false, upscale: 1.0, iconText: 0.6×, pivotX: 648.0 10-24 17:27:43.080405 10559 10559 V OCAM_ZoomSeekBar: getZoomValue, IconType: TELE zoomPointMap: {ULTRA_WIDE=0.6, WIDE=1.0, DUAL=2.0, TELE=3.5, MORE=7.0} 10-24 17:27:43.080415 10559 10559 V OCAM_ZoomSeekBar: drawTextSpecialStyle, mCurrentDisplayUnitText:× 10-24 17:27:43.080429 10559 10559 D OCAM_ZoomSeekBar: keepLatestDisplayText, type:TELE, text: 3.5, isSelected:false 10-24 17:27:43.080441 10559 10559 V OCAM_ZoomSeekBar: getClickPointType, index: 0, zoomPointMap: {ULTRA_WIDE=0.6, WIDE=1.0, DUAL=2.0, TELE=3.5, MORE=7.0}, ret:1 10-24 17:27:43.080451 10559 10559 V OCAM_ZoomSeekBar: getClickPointType, index: 0, zoomPointMap: {ULTRA_WIDE=0.6, WIDE=1.0, DUAL=2.0, TELE=3.5, MORE=7.0}, ret:1 10-24 17:27:43.080460 10559 10559 V OCAM_ZoomSeekBar: getClickPointType, index: 0, zoomPointMap: {ULTRA_WIDE=0.6, WIDE=1.0, DUAL=2.0, TELE=3.5, MORE=7.0}, ret:1 10-24 17:27:43.080473 10559 10559 V OCAM_ZoomSeekBar: drawCircleAndIconInternal, needAnimation:false, upScale: 1.0, icon: MORE, fadeIn: false, fadeOut: false, upscale: 1.0, iconText: 0.6×, pivotX: 756.0 10-24 17:27:43.080480 10559 10559 V OCAM_ZoomSeekBar: getZoomValue, IconType: MORE zoomPointMap: {ULTRA_WIDE=0.6, WIDE=1.0, DUAL=2.0, TELE=3.5, MORE=7.0} 10-24 17:27:43.080489 10559 10559 V OCAM_ZoomSeekBar: drawTextSpecialStyle, mCurrentDisplayUnitText:× 10-24 17:27:43.080502 10559 10559 D OCAM_ZoomSeekBar: keepLatestDisplayText, type:MORE, text: 7, isSelected:false 10-24 17:27:43.087307 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.087445 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.087464 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.098683 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.098777 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.098794 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.109382 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.109611 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.109632 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.120569 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.120682 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.120701 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.131623 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.131795 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.131874 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.142442 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.142491 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.142506 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.144469 2676 6395 I Camera3-Status: dumpActiveComponents: component 12 (Stream 26) is active 10-24 17:27:43.144633 2676 6395 I Camera3-Status: dumpActiveComponents: component 13 (Stream 33) is active 10-24 17:27:43.144668 2676 6395 E Camera3-Device: Camera 0: waitUntilDrainedLocked: Error waiting for HAL to drain: Connection timed out (-110) 10-24 17:27:43.154529 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.154618 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.154636 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.157666 1926 28524 I resolv : res_nsend: used send_dg 0 terrno: 110 10-24 17:27:43.165001 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.165261 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.165274 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.175409 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.175529 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.175598 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.186132 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.186169 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.186176 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.197258 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.197295 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.197302 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.208141 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.208179 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.208214 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.219029 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.219051 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.219055 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.230096 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.230132 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.230144 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.240470 2152 25128 E QC2V4l2Codec: [v4lavcE_41] RGBA8888_UBWC is not a supported pixel format! 10-24 17:27:43.240639 2152 25128 W QC2V4l2Codec: [v4lavcE_41] handleInputs: failed due to buffer incompatibility, or invalid_state[0] dropping input 10-24 17:27:43.240724 2152 25128 E QC2V4l2Codec: [v4lavcE_41] handleCodecMessage: failed to queue input buffer 10-24 17:27:43.241226 2676 6395 D CameraTraces: Process trace saved. Use dumpsys media.camera to view. 10-24 17:27:43.242505 10559 11160 E CameraCaptureSession: Session 4: Failed to create capture session; configuration failed 10-24 17:27:43.242795 10559 11161 W om.oplus.camera: Long monitor contention with owner CameraControlThread (11160) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1799) waiters=0 in void android.hardware.camera2.impl.CameraDeviceImpl$6.run() for 5.098s 10-24 17:27:43.242929 10559 11160 E CameraUnit, ProducerImpl: onSessionConfigureFail, error result: [error code: 10002, error info: stream surface error] 10-24 17:27:43.243071 10559 11160 E OCAM_OneCameraImpl: onCameraPreviewError, error: PREVIEW_CONFIG_FAILED 10-24 17:27:43.243117 10559 11160 E OCAM_AutoLogHelper: tryCatchPreviewExceptionLog , reason: PREVIEW_CONFIG_FAILED, triggerReason: -1 10-24 17:27:43.243189 10559 11161 I Quality : MonitorInfo:com.oplus.camera,run,CameraDeviceImpl.java_299,5099 10-24 17:27:43.243249 10559 11160 E OCAM_AutoLogHelper: tryCatchPreviewExceptionLog inner, reason: PREVIEW_CONFIG_FAILED 10-24 17:27:43.243390 10559 10643 I Quality : MonitorInfo:com.oplus.camera,onDeviceError,CameraDeviceImpl.java_2286,98 10-24 17:27:43.243608 10559 11160 I CameraUnit, Camera2StateMachineImpl: setDeviceState, cameraName: rear_sat, mDeviceState: SESSION_CREATING -> SESSION_CONFIGURED_FAILED 10-24 17:27:43.243941 10559 11161 D CameraUnit, StateCallback: onConfigureFailed,android.hardware.camera2.impl.CameraCaptureSessionImpl@fc22b11 10-24 17:27:43.243999 10559 11161 E CameraUnit, ProducerImpl: onSessionConfigureFail, error result: [error code: 10002, error info: stream surface error] 10-24 17:27:43.244035 10559 11161 E OCAM_OneCameraImpl: onCameraPreviewError, error: PREVIEW_CONFIG_FAILED 10-24 17:27:43.244055 10559 11161 E OCAM_AutoLogHelper: tryCatchPreviewExceptionLog , reason: PREVIEW_CONFIG_FAILED, triggerReason: -1 10-24 17:27:43.244091 10559 11161 E OCAM_AutoLogHelper: tryCatchPreviewExceptionLog inner, reason: PREVIEW_CONFIG_FAILED 10-24 17:27:43.244145 10559 11161 I CameraUnit, Camera2StateMachineImpl: setDeviceState, cameraName: rear_sat, mDeviceState: SESSION_CONFIGURED_FAILED -> SESSION_CONFIGURED_FAILED 10-24 17:27:43.244275 10559 11161 D CameraUnit, StateCallback: onError,android.hardware.camera2.impl.CameraDeviceImpl@34dce5, cameraUnit version: 6.106.63 10-24 17:27:43.244303 10559 25616 D OCAM_FeatureConflictDecision: onDataChanged: mmkv://com.oplus.camera/com.oplus.camera_preferences?class_type=java.lang.Long#preview_exception 10-24 17:27:43.244333 10559 11161 E CameraUnit, Camera2StateMachineImpl: onError, ops, camera have some error, error code: 4 10-24 17:27:43.244362 10559 25616 D OCAM_FeatureConflictDecision: getFeatureConflictMap, getFeatureConflictMap: featureKey: preview_exception, featureValueType: class java.lang.Long, has none featureInfo! 10-24 17:27:43.244394 10559 25616 D OCAM_ZoomPresenter: onDataChanged, prefKey: preview_exception 10-24 17:27:43.244445 10559 25616 V OCAM_CameraCore: onDataChanged, dataKey: preview_exception, this: com.oplus.camera.CameraManager@6bbe82d, mActivity: com.oplus.camera.Camera@e979857 10-24 17:27:43.244681 10559 25616 E OCAM_AutoLogManager: try to catch. 10-24 17:27:43.244858 10559 25616 E OCAM_AutoLogManager: prepare capture. 10-24 17:27:43.245025 10559 25616 E OCAM_AutoLogHelper: tryCatchPreviewExceptionLog onCatch, request: Request{requestReason='PREVIEW_CONFIG_FAILED', mLux=-1, mExceptionID=268505089, mMemoryAvailable=-1.0, mRunningMemoryAvailable=-1.0, mTemperature=-1.0, mCaptureModeName='common', mTimeStamp=1761298063244'}, result: CatchResult{mResultCode='failed', mDetailInfo='Interval limit denied, checkIntervalLimit: 604800000', mRequest=null} 10-24 17:27:43.245336 10559 25616 E OCAM_AutoLogManager: try to catch. 10-24 17:27:43.245417 10559 25616 D OCAM_LogCoreManager: sendException mOlcServiceInterface: com.oplus.olc.IOplusLogCore$Stub$Proxy@d850db0 10-24 17:27:43.245700 10559 25237 E OCAM_OneCameraImpl: onSessionConfigureFail, errorCode: 10002, errorInfo: stream surface error 10-24 17:27:43.245738 10559 25237 E OCAM_PreviewProcessor: onSessionConfigureFailed 10-24 17:27:43.245794 10559 25237 I OCAM_PreviewProcessor: changePreviewState, CREATING_CAPTURE_SESSION -> INIT 10-24 17:27:43.245831 10559 25237 V OCAM_OppoCamera_TRACE: traceBeginSection, msg: PreviewProcessor.raisePreviewControlEvent 10-24 17:27:43.245955 10559 11161 E CameraUnit, ProducerImpl: onCameraError, error result: [error code: 4, error info: camera device error, at: com.oplus.ocs.camera.producer.device.Camera2StateMachineImpl$1.onError(Camera2StateMachineImpl.java:128)] 10-24 17:27:43.246148 10559 25237 V OCAM_k1_BaseMode: getPictureSize, sizeList: [4096x3072, 3840x2160, 3840x1644, 3840x1608, 3280x1856, 3264x2448, 2880x2160, 2640x1200, 2624x1968, 2580x1080, 2560x1440, 2520x1080, 2344x1080, 2304x1728, 2304x1060, 2304x1048, 2160x1080, 2136x1200, 1920x1440, 1920x1280, 1920x1080, 4096x2304, 4096x1888, 4000x1818, 4000x3000, 4000x2250, 3840x2560, 3456x3456, 3136x2352, 3072x3072, 3000x3000, 2976x2232, 2944x2208, 2560x1920, 1984x1488, 1856x1392, 2016x1512, 1728x1296, 1680x1260, 1600x1200, 480x360, 480x270, 480x218, 360x360] 10-24 17:27:43.246159 10559 11161 D CameraUnit, StatisticsManager: report, mAppId: 20009, mEventId: abnormal_display, params: {pack_name=com.oplus.camera, rear_front=rear, abnormal_preview=1, camera_id=0, enter_time=1735660858753, preview_start_time=1761298042708} 10-24 17:27:43.246210 10559 11160 E CameraUnit, Camera2StateMachineImpl: handleMessage, create capture session failed. android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): waitUntilIdle:1776: Camera 0: Error waiting to drain: Connection timed out (-110) at android.hardware.camera2.utils.ExceptionUtils.throwAsPublicException(ExceptionUtils.java:75) at android.hardware.camera2.impl.ICameraDeviceUserWrapper.waitUntilIdle(ICameraDeviceUserWrapper.java:199) at android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle(CameraDeviceImpl.java:1798) at android.hardware.camera2.impl.CameraDeviceImpl.configureStreamsChecked(CameraDeviceImpl.java:732) at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSessionInternal(CameraDeviceImpl.java:1053) at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:981) at com.oplus.ocs.camera.producer.device.Camera2Impl.createNewSession(Camera2Impl.java:3136) at com.oplus.ocs.camera.producer.device.Camera2StateMachineImpl$StateMachineHandler.handleMessage(Camera2StateMachineImpl.java:413) at android.os.Handler.dispatchMessage(Handler.java:115) at android.os.Looper.loopOnce(Looper.java:298) at android.os.Looper.loop(Looper.java:408) at android.os.HandlerThread.run(HandlerThread.java:85) at com.oplus.ocs.camera.common.util.CameraHandlerThread.run(CameraHandlerThread.java:36) Caused by: android.os.ServiceSpecificException: waitUntilIdle:1776: Camera 0: Error waiting to drain: Connection timed out (-110) (code 10) at android.os.Parcel.createExceptionOrNull(Parcel.java:3384) at android.os.Parcel.createException(Parcel.java:3354) at android.os.Parcel.readException(Parcel.java:3337) at android.os.Parcel.readException(Parcel.java:3279) at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.waitUntilIdle(ICameraDeviceUser.java:984) at android.hardware.camera2.impl.ICameraDeviceUserWrapper.waitUntilIdle(ICameraDeviceUserWrapper.java:197) ... 11 more 10-24 17:27:43.246318 10559 25237 V OCAM_SizeUtils: getOptimalSizeByRatio, size: 4096x2304, targetRatio: 1.7777777777777777 precise true 10-24 17:27:43.246358 10559 25237 I OCAM_SeamlessUIControl: onPreviewStateChanged, previewState : PREVIEW_STATE_INIT 10-24 17:27:43.246379 10559 11160 D CameraUnit, Camera2StateMachineImpl: closeCameraDecision这又是什么情况,在刚刚的日志上面打印的
10-31
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值