search
HomeDatabaseMysql TutorialTopCoder 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>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.