A Odds and Ends

本文探讨了一个特定的算法问题:如何判断一个整数序列是否可以被划分为奇数个子序列,每个子序列长度为奇数且首尾元素均为奇数。通过分析给出的输入输出示例,提供了一个简单的C++程序实现。

Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?

Given an integer sequence a1, a2, …, an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.

A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.

Input
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.

The second line contains n space-separated non-negative integers a1, a2, …, an (0 ≤ ai ≤ 100) — the elements of the sequence.

Output
Output “Yes” if it’s possible to fulfill the requirements, and “No” otherwise.

You can output each letter in any case (upper or lower).

Examples
input
3
1 3 5
output
Yes
input
5
1 0 1 5 1
output
Yes
input
3
4 3 1
output
No
input
4
3 9 9 3
output
No
Note
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.

In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.

In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.

In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.

//把一个序列分成奇数个序列,每个序列奇数个数,开始和结尾都是奇数,如果可能的话输出YES,否则输出NO

#include <iostream>
#include <bits/stdc++.h>

using namespace std;
//A
int main()
{
    int n,bg,ed,fg=0,a;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(i==0)
            bg=a;
        if(i==(n-1))
            ed=a;
    }
    if(n%2==0)
        fg=1;
    else
    {
        if(bg%2==0||ed%2==0)
            fg=1;
    }
    if(fg)
        cout<<"No\n";
    else
        cout<<"Yes\n";
    return 0;
}

memory limit per test256 megabytes    You have n coins with denominations a1,a2,…,an and a natural number k . You also have a bag, which is initially empty, where you can place coins. You need to perform exactly k actions. In each action, you take one coin from those you have left and put it in your bag. After that, you can no longer take that coin. At the same time, you have a cat that loves even numbers, so every time the sum of the denominations of the coins in your bag becomes even, your cat empties the bag, meaning it takes all the coins to a place known only to it, and the bag is empty again. Note that the bag is emptied every time the sum becomes even during the process of adding coins, not just at the very last moment. Let your score be the sum of the denominations of the coins in the bag. Your task is to perform k actions such that your final score is maximized. Find the answer for all 1≤k≤n . DeepL 翻译    您有 n 枚面值为 a1,a2,…,an 的硬币和一个自然数 k 。您还有一个最初是空的袋子,可以用来放置硬币。您需要进行 k 次操作。在每次行动中,你都要从剩下的硬币中取出一枚硬币放进袋子里。之后,您就不能再拿这枚硬币了。 同时,你有一只喜欢偶数的猫,所以每当你包里的硬币面值之和变成偶数时,你的猫就会清空包,也就是说它会把所有硬币带到一个只有它自己知道的地方,然后包里的硬币就又空了。请注意,在添加硬币的过程中,每次总和变为偶数时,袋子都会被清空,而不是在最后一刻才清空。 让你的分数成为袋子里硬币面值的总和。你的任务是进行 k 次操作,使你的最终得分最大。找出所有 1≤k≤n 的答案。    Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104 ). The description of the test cases follows. The first line of each test case contains a single integer n (1≤n≤2⋅105 ) — the number of coins you have. The second line of each test case contains n natural numbers a1,a2,…,an (1≤ai≤109 ) — the denominations of the coins. It is guaranteed that the sum of n across all test cases does not exceed 2⋅105 . DeepL 翻译    输入 每个测试包含多个测试用例。第一行包含测试用例的数量 t ( 1≤t≤104 )。测试用例说明如下。 每个测试用例的第一行都包含一个整数 n ( 1≤n≤2⋅105 ) - 您拥有的硬币数量。 每个测试用例的第二行包含 n 个自然数 a1,a2,…,an ( 1≤ai≤109 )。( 1≤ai≤109 ) - 硬币的面值。 保证所有测试用例中 n 的总和不超过 2⋅105 。    Output For each test case, output n numbers — the maximum possible score that can be achieved by performing exactly k actions for all k from 1 to n . DeepL 翻译    输出 对于每个测试用例,输出 n 个数字,即从 1 到 n 的所有 k 中,执行 k 个操作所能获得的最大分数。 Example InputCopy 6 3 1 1 1 3 1 2 3 5 4 1 3 1 2 5 4 2 3 1 3 3 4 1 2 3 4 2 2 OutputCopy 1 0 1 3 5 0 3 7 9 7 9 3 7 9 7 9 1 5 7 0 0 0    Note In the first set of input data, you have coins with denominations [1,1,1 ]. k=1 : in this case, the sum of the denominations in the bag is 1 , regardless of the chosen coin. The final score is also 1 . k=2 : in this case, the sum of the denominations in the bag is initially 1 , regardless of the choice of coin. When choosing the second coin, the sum will be 2 , regardless of the choice of coin, and thus the bag will be emptied. The final score is 0 . k=3 : in this case, when choosing the first two coins, the sum will be 2 and the bag will be emptied, after which the sum will be 0 . When choosing the third coin, the sum will become 1 . In the second set of input data, you have coins with denominations [1,2,3 ]. k=1 : in this case, when choosing the coin with denomination 2 , the bag will be emptied and the final score will be 0 . When choosing the coin with denomination 1 or 3 , the final scores will be 1 and 3 , respectively. The maximum possible final score is 3 . k=2 : in this case, when choosing two coins 1 and 3 in any order, their sum will be 4 , after which the bag will be emptied and the final score will be 0 . However, when choosing 3 as the first coin, the score will be 3 . Then you can choose, for example, coin 2 , and the final score will become 5 . k=3 : in this case, the sum of all coins will be 6 , and since each time the bag is emptied it does not change the parity of the accumulated sum, the final score is 0 .
最新发布
12-13
PS C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp> npm install Debugger attached. npm warn deprecated lodash.template@4.5.0: This package is deprecated. Use https://socket.dev/npm/package/eta instead. npm warn deprecated shvl@2.0.3: older versions vulnerable to prototype pollution npm warn deprecated docsearch.js@2.6.3: This package has been deprecated and is no longer maintained. Please use @docsearch/js. npm warn deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility npm warn deprecated q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other. npm warn deprecated npm warn deprecated (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) npm warn deprecated figgy-pudding@3.5.2: This module is no longer supported. npm warn deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm warn deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm warn deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated npm warn deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm warn deprecated har-validator@5.1.5: this library is no longer supported npm warn deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x. npm warn deprecated gauge@2.7.4: This package is no longer supported. npm warn deprecated osenv@0.1.5: This package is no longer supported. npm warn deprecated are-we-there-yet@1.1.7: This package is no longer supported. npm warn deprecated npmlog@4.1.2: This package is no longer supported. npm warn deprecated fstream@1.0.12: This package is no longer supported. npm warn deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap. npm warn deprecated fs-write-stream-atomic@1.0.10: This package is no longer supported. npm warn deprecated copy-concurrently@1.0.5: This package is no longer supported. npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm warn deprecated move-concurrently@1.0.1: This package is no longer supported. npm warn deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm warn deprecated consolidate@0.15.1: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog npm warn deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained npm warn deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained npm warn deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142 npm warn deprecated @hapi/joi@15.1.1: Switch to 'npm install joi' npm warn deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained npm warn deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm warn deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address' npm warn deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated npm warn deprecated webpack-chain@4.12.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn deprecated html-webpack-plugin@3.2.0: 3.x is no longer supported npm warn deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest npm warn deprecated @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead. npm warn deprecated @babel/plugin-proposal-optional-catch-binding@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead. npm warn deprecated @babel/plugin-proposal-json-strings@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-json-strings instead. npm warn deprecated @babel/plugin-proposal-unicode-property-regex@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-unicode-property-regex instead. npm warn deprecated @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead. npm warn deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm warn deprecated vuex-persistedstate@3.2.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn deprecated vue-i18n@8.28.2: Vue I18n v8.x has reached EOL and is no longer actively maintained. About maintenance status, see https://vue-i18n.intlify.dev/guide/maintenance.html npm warn deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates. npm warn deprecated eslint-loader@3.0.4: This loader has been deprecated. Please use eslint-webpack-plugin npm warn deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js. npm warn deprecated node-sass@4.14.1: Node Sass is no longer supported. Please use `sass` or `sass-embedded` instead. npm warn deprecated axios@0.19.2: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410 npm warn deprecated eslint@5.16.0: This version is no longer supported. Please see https://eslint.org/version-support for other options. npm warn deprecated iscroll@5.2.0: deprecated npm warn deprecated mkdirp@0.3.0: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.) npm warn deprecated webpack-chain@6.5.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn deprecated glob@7.1.7: Glob versions prior to v9 are no longer supported npm warn deprecated vue@2.7.16: Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details. npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported npm warn deprecated webpack-chain@6.5.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn cleanup Failed to remove some directories [ npm warn cleanup [ npm warn cleanup '\\\\?\\C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules', npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\@hapi'] { npm warn cleanup errno: -4048, npm warn cleanup code: 'EPERM', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@hapi' npm warn cleanup } npm warn cleanup ], npm warn cleanup [ npm warn cleanup '\\\\?\\C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@vue', npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\@vue\compiler-core\node_modules'] { npm warn cleanup errno: -4048, npm warn cleanup code: 'EPERM', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@vue\\compiler-core\\node_modules' npm warn cleanup } npm warn cleanup ], npm warn cleanup [ npm warn cleanup '\\\\?\\C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@vuepress', npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\@vuepress'] { npm warn cleanup errno: -4048, npm warn cleanup code: 'EPERM', npm warn cleanup syscall: 'rmdir', npm warn cleanup path: 'C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\@vuepress' npm warn cleanup } npm warn cleanup ] npm warn cleanup ] npm error code 1 npm error path C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\node-sass npm error command failed npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js npm error Building: C:\Program Files\nodejs\node.exe C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= npm error Debugger attached. npm error Debugger attached. npm error gyp info it worked if it ends with ok npm error gyp verb cli [ npm error gyp verb cli 'C:\\Program Files\\nodejs\\node.exe', npm error gyp verb cli 'C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\node-gyp\\bin\\node-gyp.js', npm error gyp verb cli 'rebuild', npm error gyp verb cli '--verbose', npm error gyp verb cli '--libsass_ext=', npm error gyp verb cli '--libsass_cflags=', npm error gyp verb cli '--libsass_ldflags=', npm error gyp verb cli '--libsass_library=' npm error gyp verb cli ] npm error gyp info using node-gyp@3.8.0 npm error gyp info using node@24.3.0 | win32 | x64 npm error gyp verb command rebuild [] npm error gyp verb command clean [] npm error gyp verb clean removing "build" directory npm error gyp verb command configure [] npm error gyp verb check python checking for Python executable "python2" in the PATH npm error gyp verb `which` failed Error: not found: python2 npm error gyp verb `which` failed at getNotFoundError (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:13:12) npm error gyp verb `which` failed at F (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:68:19) npm error gyp verb `which` failed at E (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:80:29) npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:89:16 npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\isexe\index.js:42:5 npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\isexe\windows.js:36:5 npm error gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:189:21) npm error gyp verb `which` failed python2 Error: not found: python2 npm error gyp verb `which` failed at getNotFoundError (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:13:12) npm error gyp verb `which` failed at F (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:68:19) npm error gyp verb `which` failed at E (C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:80:29) npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\which\which.js:89:16 npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\isexe\index.js:42:5 npm error gyp verb `which` failed at C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\isexe\windows.js:36:5 npm error gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:189:21) { npm error gyp verb `which` failed code: 'ENOENT' npm error gyp verb `which` failed } npm error gyp verb check python checking for Python executable "python" in the PATH npm error gyp verb `which` succeeded python C:\Python313\python.EXE npm error (node:3656) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead. npm error (Use `node --trace-deprecation ...` to show where the warning was created) npm error gyp ERR! configure error npm error gyp ERR! stack Error: Command failed: C:\Python313\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3]; npm error gyp ERR! stack File "<string>", line 1 npm error gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3]; npm error gyp ERR! stack ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ npm error gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? npm error gyp ERR! stack npm error gyp ERR! stack at genericNodeError (node:internal/errors:983:15) npm error gyp ERR! stack at wrappedFn (node:internal/errors:537:14) npm error gyp ERR! stack at ChildProcess.exithandler (node:child_process:415:12) npm error gyp ERR! stack at ChildProcess.emit (node:events:507:28) npm error gyp ERR! stack at maybeClose (node:internal/child_process:1101:16) npm error gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:305:5) npm error gyp ERR! System Windows_NT 10.0.26100 npm error gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\fcube-app\\W11.F-CUBE-A-APP\\CL_CSM\\src\\main\\webapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" npm error gyp ERR! cwd C:\fcube-app\W11.F-CUBE-A-APP\CL_CSM\src\main\webapp\node_modules\node-sass npm error gyp ERR! node -v v24.3.0 npm error gyp ERR! node-gyp -v v3.8.0 npm error gyp ERR! not ok npm error Waiting for the debugger to disconnect... npm error Build failed with error code: 1 npm error Waiting for the debugger to disconnect... npm error A complete log of this run can be found in: D:\node\node_cache\_logs\2025-08-22T05_02_59_796Z-debug-0.log Waiting for the debugger to disconnect...
08-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值