TopCoder SRM 634 Div.2[ABC]
TopCoder SRM 634 Div.2[ABC] ACM 题目地址:TopCoder SRM 634 赛后做的,感觉现场肯定做不出来Orz,简直不能多说。 Level One-MountainRanges 【水题】 题意 : 问序列中有几个完全大于旁边的峰。 分析 : 傻题,不多说。 代码 : /** Author: illuz iilluze
TopCoder SRM 634 Div.2[ABC]
ACM
题目地址: TopCoder SRM 634
赛后做的,感觉现场肯定做不出来Orz,简直不能多说。
Level One-MountainRanges【水题】
题意:
问序列中有几个完全大于旁边的峰。
分析:
傻逼题,不多说。
代码:
/* * Author: illuz <iilluzen> * File: one.cpp * Create Date: 2014-09-26 21:01:23 * Descripton: */ #include <cstdio> #include <vector> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define repf(i,a,b) for(int i=(a);i h) { int ret = 0, sz = h.size(); if (sz == 1) { return 1; } if (sz == 2) { return h[0] != h[1]; } if (h[0] > h[1]) ret++; if (h[sz - 1] > h[sz - 2]) ret++; // cout h[i - 1] && h[i] > h[i + 1]) ret++, i++; } return ret; } }; int main() { // ios_base::sync_with_stdio(0); MountainRanges a; int n, t; vector<int> v; cin >> n; while (n--) { cin >> t; v.push_back(t); } cout <br> <br> <hr> <h2> <span>Level Two-ShoppingSurveyDiv2</span>【数学】</h2> <p> <span>题意</span>: <br> 你在做一项调查,一共有N人参加了调查,你得到了一份调查结果,就是每样东西有几个人买过。 <br> 现在你只有这份调查结果,即:第i个物品有s[i]个人买过。 <br> 问你最少有几个人全部东西都买过。</p> <p> <span>分析</span>:</p> <p> 我们可以考虑有多少人次的东西没人买,即每样东西本来应该N人全都有买的,没人买就是<code>sum(N - s[i])</code>。 <br> 这时候我们可以把这些东西尽量分配给每个人,那么剩下的人就是没办法只能全买的了,也就是最少的。如果够分(<code>N >= sum(N - s[i])</code>),那所有人都有可能没买全了。</p> <p> <span>代码</span>:</p> <pre class="brush:php;toolbar:false">/* * Author: illuz <iilluzen> * File: two.cpp * Create Date: 2014-09-26 22:36:58 * Descripton: */ #include <cstdio> #include <vector> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define repf(i,a,b) for(int i=(a);i s) { int sz = s.size(), sum = 0; repf (i, 0, sz - 1) sum += s[i]; int t = N - (N * sz - sum); if (t v; cin >> n >> m; repf (i, 0, m - 1) { cin >> t; v.push_back(t); } ShoppingSurveyDiv2 a; cout <br> <br> <hr> <h2> <span>Level Three-SpecialStrings</span>【构造】</h2> <p> <span>题意</span>: <br> 设定一种特殊的串 <br> 1. 01串 <br> 2. 从任何位置把它分为两个前后串,前面的字典序总是小于后面的。</p> <p> 现在给出一个保证特殊的串,问你同个长度下的字典序的下一个串是什么,如果是最后一个就返回空。</p> <p> <span>分析</span>:</p> <p> 很明显,这个串必须是字典序的下一个,也就是这个01串是要进位的,所以我们先给它+1,即把最后一个0变成1,后面都变成X表示未知。 <br> 以<code>01101111011110111</code>作为例子,变化后就是<code>01101111011111XXX</code>了。</p> <p> 后面全放0能符合条件2吗?很明显不能</p> <p> 我们先考虑修改点的前面部分。 <br> 由于修改之前的那部分都已经严格遵守条件2了,而原先那个0的位置被变成1,所以:以前面的位置作为分割点的话,后半串是比原来变得更大了,所以前面部分不需要更改。</p> <p> <span>主要问题在后面部分,我们已修改点为分割点,还是按刚才那个例子,前后串就变成</span><code>01101111011111</code><span>和</span><code>XXX</code><span>了。 </span><br> <span>那么后面的X串就要比前面大了,由于要是下一个字典序,所以X串直接可以拷前面部分,</span><span><del>然后+1就行了</del></span><span>。 </span><br> <span><span>这里有个错误:仅仅“X串直接可以拷前面部分,然后+1”这样是不行的,不是+1,而是要找拷贝完的X串的下一个合法串,所以我们继续找最后一个0、拷贝直到最后0在最后一个位置为止。(谢谢forgot93巨巨留言提醒)</span></span></p> <p> 如何证明这个串在分割点为后面时,也能符合条件2呢,很明显,由于后面部分是完全复制前面的+1,所以分割点在后面跟分割点在后面是一样的,前面的是已经保证符合条件2的,所以后面肯定没问题。想一下就明白了。</p> <p> 这样一来,这个串就求出来了。</p> <p> <span>代码</span>:</p> <pre class="brush:php;toolbar:false">/* * Author: illuz <iilluzen> * File: three.cpp * Create Date: 2014-09-26 21:57:10 * Descripton: */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define repf(i,a,b) for(int i=(a);i= 0; i--) { if (s[i] == '0') { pos = i; break; } } if (pos == 0) return ""; for (int i = len - 1; i >= 0; i--) { if (s[i] == '0') { s[i] = '1'; // 修改及复制 repf (j, i + 1, len - 1) s[j] = s[j - i - 1]; if (i == len - 1) // 如果是0在最后一个就结束 return s; else // 否则让i=len重后面再找 i = len; } } return s; } }; int main() { // ios_base::sync_with_stdio(0); SpecialStrings a; string s; cin >> s; cout <br> <br> <p><br> </p> </algorithm></iostream></cstring></cstdio></iilluzen>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.
