목차
A. Pasha and Pixels
Code:
B. Anton and currency you all know
Another Code:
C. Anya and Ghosts
데이터 베이스 MySQL 튜토리얼 第二十七次codeforces竞技结束 #288 Div 2

第二十七次codeforces竞技结束 #288 Div 2

Jun 07, 2016 pm 03:07 PM
div 마치다

Problems # Name A Pasha and Pixels standard input/output 2 s, 256 MB x3234 B Anton and currency you all know standard input/output 0.5 s, 256 MB x2848 C Anya and Ghosts standard input/output 2 s, 256 MB x1671 这次出了前三题,原为第三位的Av

Problems

第二十七次codeforces竞技结束 #288 Div 2

 

 

# Name    
A

Pasha and Pixels

standard input/output

2 s, 256 MB
第二十七次codeforces竞技结束 #288 Div 2 第二十七次codeforces竞技结束 #288 Div 2 第二十七次codeforces竞技结束 #288 Div 2 x3234
B

Anton and currency you all know

standard input/output

0.5 s, 256 MB
第二十七次codeforces竞技结束 #288 Div 2 第二十七次codeforces竞技结束 #288 Div 2 第二十七次codeforces竞技结束 #288 Div 2 x2848
C

Anya and Ghosts

standard input/output

2 s, 256 MB
第二十七次codeforces竞技结束 #288 Div 2 第二十七次codeforces竞技结束 #288 Div 2 第二十七次codeforces竞技结束 #288 Div 2 x1671

这次出了前三题,原为第三位的Avator加了100来分变成第二了,这下终于三个ID都1650+了,可喜可贺,希望能多撑几天吧……


A. Pasha and Pixels

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.

Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with mpixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2?×?2 square consisting of black pixels is formed.

Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers iand j, denoting respectively the row and the column of the pixel to be colored on the current move.

Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2?×?2 square consisting of black pixels is formed.

Input

The first line of the input contains three integers n,?m,?k (1?≤?n,?m?≤?10001?≤?k?≤?105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.

The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1?≤?i?≤?n1?≤?j?≤?m), representing the row number and column number of the pixel that was painted during a move.

Output

If Pasha loses, print the number of the move when the 2?×?2 square consisting of black pixels is formed.

If Pasha doesn't lose, that is, no 2?×?2 square consisting of black pixels is formed during the given k moves, print 0.

Sample test(s)

input

2 2 4
1 1
1 2
2 1
2 2
로그인 후 복사

output

4
로그인 후 복사

input

2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
로그인 후 복사

output

5
로그인 후 복사

input

5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
로그인 후 복사

output

0
로그인 후 복사



给你一个n*m的棋盘,每次你走到的格子都会被涂黑,接下来有k步,每一步都告诉你我这步走的是哪一个格子(Row/Col坐标),要求输出在第几步时第一次出现了2X2的黑色正方形,如果走完了都没出现,则输出0。

看了看数据范围,似乎……模拟完全无压呢

我们就真的给一个棋盘,每走一步我们就把这个格子 mp[a][b]=1 标记一下,然后找左上右上左下右下,这四个2X2的正方形是不是全黑,是的话输出然后return,不是的话就继续咯~

Code:

#include <cmath> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a) b;
}

int mp[1002][1002]={0};

bool judge(int r,int c)
{
	if(mp[r-1][c]==1)
	{
		if(mp[r][c-1]==1)
		{
			if(mp[r-1][c-1]==1)return true;
		}
		if(mp[r][c+1]==1)
		{
			if(mp[r-1][c+1]==1)return true;
		}
	}
	if(mp[r+1][c]==1)
	{
		if(mp[r][c-1]==1)
		{
			if(mp[r+1][c-1]==1)return true;
		}
		if(mp[r][c+1]==1)
		{
			if(mp[r+1][c+1]==1)return true;
		}
	}
	return false;
}

int main()
{
	int n,m,k;	cin>>n>>m>>k;
	for(int i=1;i<br>
<br>


<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<h2 id="B-Anton-and-currency-you-all-know">B. Anton and currency you all know</h2>
<p>
</p>
<p>
time limit per test</p>
0.5 seconds
<p>
</p>
<p>
memory limit per test</p>
256 megabytes
<p>
</p>
<p>
input</p>
standard input
<p>
</p>
<p>
output</p>
standard output

<p>
</p>
<p>
Berland, 2016. The exchange rate of <span>currency you all know</span> against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is
 now assumed to be an integer.</p>
<p>
Reliable sources have informed the financier Anton of some information about the exchange rate of <span>currency you all know</span> against the burle for tomorrow. Now Anton knows that tomorrow the exchange
 rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that
 today the exchange rate is an <span>odd</span> positive integer <span><em>n</em></span>. Help Anton to determine the exchange
 rate of <span>currency you all know</span> for tomorrow!</p>

<p>
</p>
<p>
Input</p>
<p>
The first line contains an odd positive integer <span><em>n</em></span> — the exchange rate of <span>currency you all know</span> for
 today. The length of number <span><em>n</em></span>'s representation is within range from <span>2</span> to <span>10<span>5</span></span>,
 inclusive. The representation of <span><em>n</em></span> doesn't contain any leading zeroes.</p>

<p>
</p>
<p>
Output</p>
<p>
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <span>?-?1</span>.</p>
<p>
Otherwise, print the exchange rate of <span>currency you all know</span> against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's
 exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.</p>

<p>
</p>
<p>
Sample test(s)</p>
<p>
</p>
<p>
</p>
<p>
input</p>
<pre class="brush:php;toolbar:false">527
로그인 후 복사

output

572
로그인 후 복사

input

4573
로그인 후 복사

output

3574
로그인 후 복사

input

1357997531
로그인 후 복사

output

-1
로그인 후 복사
로그인 후 복사



给一个很长的数字,至少两位数,最多10的五次方位的一个奇数,让你调换其中两个数位,将其变为可变的各种选择中最大的偶数并输出,如果做不到则输出-1。

很显然,最后一位决定了奇偶,所以调换的两位中确定了一位是末位,然后,做不到的意思就是数字中没有偶数数字,特例排除后我们来考虑如何最大。

因为数字太大,所以我们不能直接加减甚至无法记录最大值,但是我们在纸上写一写就能发现,很明显调换后与调换前的差一定是一个 A99999...999B 的数,而AB作为一个两位数来看就是两个调换位调换前后的两位数的差,即 10*B+A-10*A-B=9*(B-A) ,连9我们都不必要了…… 我们就简单的通过正负(zf)、9的个数(digit)和差值(sub)来记录就可以啦~ 话说我为啥要把正负提出来!!! 直接正负和差值用一个int不就可以了么!我真傻……真的……

Code:

#include <map>
#include <cmath> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a) b;
}

string s;	
string ans;
int zf,digit,sub;
int tzf,td,ts,len; //temp zf,dig,sub
map<int> m;

void update(int pos)
{
	zf=tzf;
	digit=td;
	sub=ts;
	ans=s;
	char temp=ans[pos];
	ans[pos]=ans[len-1];
	ans[len-1]=temp;
}

int main()
{
	m.clear();
	cin>>s;
	len=s.length();
	int tail=s[len-1]-'0';
	for(int i=0;i<len int num="s[i]-'0';" if m cout return zf="-1,digit=100001,sub=99;" tzf="0,td=0,ts=0;" for>::iterator it=m.begin(); it!=m.end(); ++it)
	{
		//cout first  " second first;
		int now=s[pos]-'0';
		tzf=1;
		ts=tail-now; //*9 略去 
		td=s.length()-pos;
		if(tszf) update(pos);
		else if(tzf==1 && zf==1)
		{
			if(td>digit) update(pos);
			else if(td==digit)
			{
				if(ts>sub) update(pos);
			}
		}
		else if(tzf==-1 && zf==-1)
		{
			if(td<digit update else if cout return><br>

<h3 id="Another-Code">Another Code:</h3>

<pre class="brush:php;toolbar:false">#include<stdio.h>
#include<string.h>
int n,i,x,minpos=-1;
char a[100010],t;
int main(){
    scanf("%s",a);
    n=strlen(a);
    for(i=0;i<n-1 if>a[i]){
                t = a[n-1] , a[n-1] = a[i] , a[i] = t;
                printf("%s\n",a);
                return 0;
            }
            else{
                minpos = i;
            }
        }
    }
    if(minpos==-1){
        printf("-1\n");
    }
    else{
        t = a[n-1] , a[n-1] = a[minpos] , a[minpos] = t;
        printf("%s\n",a);
        return 0;
    }
}</n-1></string.h></stdio.h>
로그인 후 복사


C. Anya and Ghosts

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.

For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.

What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.

Input

The first line contains three integers mtr (1?≤?m,?t,?r?≤?300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.

The next line contains m space-separated numbers wi (1?≤?i?≤?m1?≤?wi?≤?300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.

Output

If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.

If that is impossible, print ?-?1.

Sample test(s)

input

1 8 3
10
로그인 후 복사

output

3
로그인 후 복사

input

2 10 1
5 8
로그인 후 복사

output

1
로그인 후 복사

input

1 1 3
10
로그인 후 복사

output

-1
로그인 후 복사
로그인 후 복사

Note

Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.

It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.

In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.

In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.

In the third sample test the answer is ?-?1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.


安娜是个小姑娘,有m只鬼晚上要来安娜家(鬼登门拜访的时间以升序给出),小姑娘每秒钟可以点燃1根蜡烛,蜡烛可以燃烧t秒,每只鬼到她家的时候她家需要有至少r根蜡烛在燃烧,问最少用多少根蜡烛可以渡过难关。

首先我们需要考虑“-1”即做不到,是什么情况,每秒都在点蜡烛但是在任何一秒都无法实现同时有r根蜡烛在亮着,那么,m

当m>=r时,我们在任一根蜡烛燃烧的最后一秒时点燃一根蜡烛,蜡烛熄灭的同时新蜡烛燃烧第一秒,就可以达成延续r根蜡烛的状态。首先,第一只鬼来的时候很明显为了不浪费蜡烛的持续时间,我们从鬼来的前一秒点燃开始向前推,前1秒到前r秒都在点蜡烛,这时在第一个鬼来的时候刚好r根蜡烛而且他们总剩余燃烧时间最大,什么你问我如果鬼第一秒就来了怎么点?仔细看题:That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.

然后我们用lgt(light)数组来记录每一秒的当前亮度是多少,为了得知某根蜡烛啥时候灭,我们在点燃的时候就在lgt[当前秒数+t]处赋值-1,这样dp推到那里的时候就会自动减一达到减少的效果了,我们从第一秒开始推,当遇到鬼了我们要看现在光够不够,不够的话从前一秒开始向前补蜡烛,然后一路向后,最终蜡烛数必然是最小,也算是一个贪心dp的感觉吧

Code:

#include <cmath> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a) b;
}

int vit[666]={0};
int lgt[666]={0};	//degree of light

int main()
{	
	int c=0;
	int m,t,r;	cin>>m>>t>>r;
	if(t<r for i="1;i<=m;i++)" scanf int now="1;" lgt if dec="r-lgt[i];" c vt="i+t;i+t-vt<dec;vt--)" cout return><br>
<br>
</r></algorithm></iostream></cstring></cstdlib></string></cstdio></cctype></cmath>
로그인 후 복사







본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Teamfight Tactics S11은 언제 종료되나요? Teamfight Tactics S11은 언제 종료되나요? Mar 18, 2024 pm 03:16 PM

Teamfight Tactics의 각 시즌은 약 3개월 동안 진행됩니다. 현재 Teamfight Tactics S11 시즌의 미국 테스트 서버는 3월 7일에 업데이트되어 출시될 예정입니다. Teamfight Tactics와 Golden Shovel은 3월 21일에 업데이트되어 출시될 예정입니다. 시즌 아마도 7월 초에 끝날 것 같습니다. TFT S11은 언제 종료되나요? 답변: 7월 초. 1. S11 시즌이 7월 초에 종료될 것으로 예상되며, 구체적인 종료일은 공식 발표를 기다려봐야 할 것 같습니다. 2. Teamfight Tactics의 각 시즌은 약 3개월 동안 지속됩니다. 3. Teamfight Tactics S11 시즌의 미국 테스트 서버는 3월 7일에 업데이트되어 출시될 예정이며, Teamfight Tactics와 Golden Shovel은 3월 21일에 업데이트되어 출시될 예정입니다. 4. S11 시즌에는 새로운 게임플레이 메커니즘이 추가되고, 20개 이상의 오른 아티팩트가 추가됩니다.

Win11 백그라운드에서 실행되는 단축키를 빠르게 끄는 방법은 무엇입니까? Win11 백그라운드에서 실행되는 단축키를 빠르게 끄는 방법은 무엇입니까? Dec 28, 2023 am 09:54 AM

컴퓨터를 사용하다 보면 필연적으로 백그라운드에서 계속 실행되어 시스템 속도가 느려지는 문제가 많이 발생하게 되는데, 이때 win11에서 백그라운드 실행을 종료할 수 있는 단축키가 과연 있을까요? 단축키를 사용하여 작업 관리자를 닫은 다음 Backstage를 닫습니다. win11에서 백그라운드 실행을 종료하는 단축키: 1. 먼저 키보드의 "ctrl+shift+esc" 단축키 조합을 눌러 작업 관리자 페이지를 엽니다. 2. 작업 관리자 페이지에서 마우스를 사용하여 "이름" 버튼 옵션을 클릭하고 선택합니다. 3. 페이지 이동 후 현재 실행 중인 모든 "백그라운드 프로세스"를 직접 볼 수 있습니다. 4. 실제 필요에 따라 닫으려는 배경을 선택하고 옵션 오른쪽 하단에 있는 "작업 끝내기"를 클릭합니다.

컴퓨터 작업 관리자 바로 가기 키를 사용하여 작업을 종료하는 방법 컴퓨터 작업 관리자 바로 가기 키를 사용하여 작업을 종료하는 방법 Jan 02, 2024 pm 01:34 PM

많은 친구들이 컴퓨터를 사용할 때 특정 소프트웨어가 멈추는 현상을 경험합니다. 컴퓨터가 움직일 수 없으면 작업 관리자를 불러와 작업을 종료해야 합니다. 작업을 호출한 후 단축키를 사용하여 작업을 종료하는 방법이 가장 쉬운데, 다른 방법도 살펴보겠습니다. 아래를 살펴보세요. 작업 관리자에서 작업을 종료하기 위한 단축키를 사용하는 방법 작업 관리자에서 단축키를 사용하는 방법: 1. 키 조합 "Ctrl+Shift+ESC". 2. 키 조합 "Ctrl+Alt+Delete". 작업 종료 단축키 1. 종료할 작업을 선택하고 '삭제'를 클릭하세요. 2. 종료해야 하는 작업을 선택하고 "alt+e" 키 조합을 누르십시오.

CSS를 사용하여 div에 모서리가 누락되었음을 인식하는 방법 CSS를 사용하여 div에 모서리가 누락되었음을 인식하는 방법 Jan 30, 2023 am 09:23 AM

div에 모서리가 없음을 인식하는 CSS 방법: 1. HTML 샘플 파일을 만들고 div를 정의합니다. 2. div의 너비와 높이 배경색을 설정합니다. 3. 삭제해야 하는 div에 의사 클래스를 추가합니다. 모서리를 지정하고 의사 클래스를 배경색과 동일한 색상 사용으로 설정한 다음 45도 회전한 다음 제거해야 할 모서리에 배치합니다.

Tencent Meeting에서 회의를 종료하는 방법 - Tencent Meeting에서 회의를 종료하기 위한 특정 작업 Tencent Meeting에서 회의를 종료하는 방법 - Tencent Meeting에서 회의를 종료하기 위한 특정 작업 Mar 05, 2024 pm 12:16 PM

사무실에서 Tencent Meeting 소프트웨어를 자주 사용하시나요? 그렇다면 Tencent Meeting에서 회의를 종료하는 방법을 아시나요? 다음으로 편집자가 Tencent Meeting에서 회의를 종료하는 구체적인 방법을 알려드리겠습니다. 아래를 살펴보겠습니다. 컴퓨터를 켜고 두 번 클릭하여 Tencent Meeting에 입장한 다음 로그인하고 클릭하여 빠른 회의에 입장한 다음 회의 종료 버튼을 클릭합니다.

ChatGPT API를 기반으로 한 단어 표시 번역 브라우저 스크립트 구현 ChatGPT API를 기반으로 한 단어 표시 번역 브라우저 스크립트 구현 May 01, 2023 pm 03:28 PM

머리말 최근에는 GitHub에 ChatGPTAPI 기반의 브라우저 스크립트인 openai-translator가 있습니다. 단기간 내에 번역 지원 외에도 다듬기 및 요약 기능도 지원됩니다. -ins, 또한 Tauri 패키징을 사용합니다. Tauri가 Rust 부분을 사용한다는 사실을 제외하면, 브라우저 부분은 여전히 ​​수동으로 구현하기가 쉽습니다. 예를 들어 openAI에서 제공하는 인터페이스에서는 다음 코드를 복사하고 브라우저 콘솔에서 요청을 시작하여 번역을 완료할 수 있습니다. //예제 constOPENAI_API_KEY="s

iframe과 div의 차이점은 무엇입니까 iframe과 div의 차이점은 무엇입니까 Aug 28, 2023 am 11:46 AM

iframe과 div의 차이점은 iframe은 주로 다른 웹사이트의 콘텐츠를 로드하거나 웹페이지를 여러 영역으로 나눌 수 있는 외부 콘텐츠를 도입하는 데 사용된다는 점입니다. 레이아웃 및 스타일 제어를 위해 콘텐츠를 구성합니다.

div 상자 모델은 무엇입니까 div 상자 모델은 무엇입니까 Oct 09, 2023 pm 05:15 PM

div 상자 모델은 웹 페이지 레이아웃에 사용되는 모델입니다. 이 모델은 콘텐츠 영역, 패딩, 테두리 및 여백의 네 부분으로 구성됩니다. div 박스 모델의 장점은 웹 페이지의 레이아웃과 요소 사이의 간격을 쉽게 제어할 수 있다는 것입니다. 콘텐츠 영역의 크기, 내부 여백, 테두리 및 외부 여백을 조정하여 다양한 레이아웃 효과를 얻을 수 있습니다. 상자 모델은 또한 일부 속성을 제공하며 메서드는 CSS 및 JavaScript를 통해 상자의 스타일과 동작을 동적으로 변경할 수 있습니다.

See all articles