A - Pasha and Pixels
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[2000][2000];
int main()
{
int n,m,k,row,lie;
while(~scanf("%d %d %d",&n,&m,&k))
{
memset(a,0,sizeof(a));
int e=0;
for(int i=1; i<=k; i++)
{
scanf("%d %d",&row,&lie);
a[row][lie]=1;
if(e)
continue;
if(row==1&&lie==1)
{
if(a[1][1]==1&&a[1][2]==1&&a[2][1]==1&&a[2][2]==1)
{
if(e==0)
e=i;
}
}
else if(row==1&&lie>1)
{
if(a[1][lie]==1&&a[2][lie]==1&&a[1][lie+1]==1&&a[2][lie+1]==1)
{
if(e==0)
e=i;
}
else if(a[1][lie]==1&&a[2][lie]==1&&a[1][lie-1]==1&&a[2][lie-1]==1)
{
if(e==0)
e=i;
}
}
else if(lie==1&&row>1)
{
if(a[row][1]==1&&a[row][2]==1&&a[row+1][1]==1&&a[row+1][2]==1)
{
if(e==0)
e=i;
}
else if(a[row][1]==1&a[row][2]==1&&a[row-1][1]==1&&a[row-1][2]==1)
{
if(e==0)
e=i;
}
}
else
{
if(a[row][lie]==1&&a[row][lie+1]==1&&a[row+1][lie]==1&&a[row+1][lie+1]==1)
{
if(e==0)
e=i;
}
else if(a[row][lie]==1&&a[row+1][lie]==1&&a[row][lie-1]==1&&a[row+1][lie-1]==1)
{
if(e==0)
e=i;
}
else if(a[row][lie]==1&&a[row-1][lie]==1&&a[row][lie-1]==1&&a[row-1][lie-1]==1)
{
if(e==0)
e=i;
}
else if(a[row][lie]==1&&a[row-1][lie]==1&&a[row][lie+1]==1&&a[row-1][lie+1]==1)
{
if(e==0)
e=i;
}
}
}
printf("%d\n",e);
}
return 0;
}
<span style="font-size: 24px; text-align: center; color: green;"><strong>B - </strong></span><span style="color: rgb(0, 0, 255); font-size: 24px; text-align: center;"><strong>Anton and currency you all know</strong></span>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char a[200000],str[200000];
int main()
{
while(~scanf("%s",a))
{
strcpy(str,a);
int len=strlen(a);
int maxid1=-1,maxid2=-1;
for(int i=0; i<len-1; i++)
{
int b=a[i]-'0';
int d=a[len-1]-'0';
if(b%2==0)
{
if(d>b)
{
maxid1=i;
break;
}
else
{
maxid2=i;
}
}
}
//printf("%d %d\n",maxid1,maxid2);
if(maxid1!=-1)
{
char t=a[maxid1];
a[maxid1]=a[len-1];
a[len-1]=t;
}
else if(maxid1==-1&&maxid2!=-1)
{
char t=a[maxid2];
a[maxid2]=a[len-1];
a[len-1]=t;
}
else
{
printf("-1\n");
continue;
}
/*int c=strcmp(a,str);
if(c==1)
puts(a);
else
printf("-1\n");*/
puts(a);
}
return 0;
}
c题一道简单的贪心,只要注意一下到底是什么时候算是蜡烛燃烧,开始的时候鬼来的时间可以小于k,因为你可以0点以前就点燃蜡烛
C - Anya and Ghosts
Description
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 m, t, r (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 ≤ m, 1 ≤ 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 Input
1 8 3 10
3
2 10 1 5 8
1
1 1 3 10
-1
Hint
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int m,t,k;
int s=0;
int a[2000],b[2000];
while(~scanf("%d %d %d",&m,&t,&k))
{
for(int i=0; i<m; i++)
scanf("%d",&a[i]);
sort(a,a+m);
if(t<k)
{
printf("-1\n");
continue;
}
else
{
s=k;
for(int i=0; i<k; i++)
b[i]=t-i;
for(int i=1; i<m; i++)
{
int ti=a[i]-a[i-1];
int l=0;
for(int j=0; j<k; j++)
{
if(b[j]-ti<=0)
{
b[j]=t-l;
l++;
s++;
}
else
b[j]=b[j]-ti;
}
}
}
printf("%d\n",s);
}
return 0;
}