总结:
这一次前两个都是水题,着重模拟能力,题意能看的明确,只是一些小细节考虑的不清楚,所以做题还是应该多加细心,做题脑子要清晰,脑子要够用,加油!!!????。
A. Cashier
input
standard input
output
standard output
Vasya has recently got a job as a cashier at a local store. His day at work is LL minutes long. Vasya has already memorized nn regular customers, the ii-th of which comes after titi minutes after the beginning of the day, and his service consumes lili minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer.
Vasya is a bit lazy, so he likes taking smoke breaks for aa minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
Input
The first line contains three integers nn, LL and aa (0≤n≤1050≤n≤105, 1≤L≤1091≤L≤109, 1≤a≤L1≤a≤L).
The ii-th of the next nn lines contains two integers titi and lili (0≤ti≤L−10≤ti≤L−1, 1≤li≤L1≤li≤L). It is guaranteed that ti+li≤ti+1ti+li≤ti+1 and tn+ln≤Ltn+ln≤L.
Output
Output one integer — the maximum number of breaks.
Examples
input
2 11 3
0 1
1 1
output
Copy
3
input
0 5 2
output
2
input
1 3 2
1 2
output
0
Note
In the first sample Vasya can take 33 breaks starting after 22, 55 and 88 minutes after the beginning of the day.
In the second sample Vasya can take 22 breaks starting after 00 and 22 minutes after the beginning of the day.
In the third sample Vasya can't take any breaks.
题意:有n行是工作的时间,分别是开始时间与结束时间,在他不工作的时候,可以去吸烟,每间隔a分钟吸一次烟,问在不影响为顾客服务的时候,可以吸烟多少次。
模拟即可,用数组来模拟他开始工作与结束的时间,并且再判断不工作的时间段是否够他吸一次烟即可。
#include<iostream>
#include<cstdio>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
using namespace std;
int num1[1000100],num2[100100];
int main()
{
int n,l,a;
int cnt,sum;
scanf("%d%d%d",&n,&l,&a);
for(int i=0;i<n;i++)
{
scanf("%d%d",&num1[i],&num2[i]);
}
cnt=0;
sum=0;
for(int i=0;i<n;i++)
{
cnt+=(num1[i]-sum)/a;
sum=num1[i]+num2[i];
}
int L=(l-sum);
printf("%d\n",cnt+(L/a));
return 0;
}
B. Forgery
input
standard input
output
standard output
Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?
For simplicity, the signature is represented as an n×mn×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×33×3square without its central cell if it is completely contained inside the grid, as shown below.
xxx
x.x
xxx
Determine whether is it possible to forge the signature on an empty n×mn×m grid.
Input
The first line of input contains two integers nn and mm (3≤n,m≤10003≤n,m≤1000).
Then nn lines follow, each contains mm characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.
Output
If Andrey can forge the signature, output "YES". Otherwise output "NO".
You can print each letter in any case (upper or lower).
Examples
input
3 3
###
#.#
###
output
YES
input
3 3
###
###
###
output
NO
input
4 3
###
###
###
###
output
YES
input
5 7
.......
.#####.
.#.#.#.
.#####.
.......
output
YES
Note
In the first sample Andrey can paint the border of the square with the center in (2,2)(2,2).
In the second sample the signature is impossible to forge.
In the third sample Andrey can paint the borders of the squares with the centers in (2,2)(2,2) and (3,2)(3,2):
- we have a clear paper:
... ... ... ... - use the pen with center at (2,2)(2,2).
### #.# ### ... - use the pen with center at (3,2)(3,2).
### ### ### ###
In the fourth sample Andrey can paint the borders of the squares with the centers in (3,3)(3,3) and (3,5)(3,5).
模拟题:基本图形是
###
#.#
###
题目给出的图形,是否可以通过上面那个基本图形转化而来,‘.’代表空,‘#’代表有填充物,我们就假设原始图形都是 . ,然后用题目给出的基本图形在上面绘图,看是否能够画出与题目给出的图形一样,能就输出YES,不能就输出NO。
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=1010;
char g[maxn][maxn];
int flag[maxn][maxn];
int n,m;
int dir[8][2]={1,-1,-1,1,1,1,-1,-1,1,0,0,1,-1,0,0,-1};
int check(int x,int y)
{
for(int i=0;i<8;i++)
{
int xx=x+dir[i][0];
int yy=y+dir[i][1];
if(g[xx][yy]=='.')
return 0;
}
return 1;
}
void change(int x,int y)
{
for(int i=0;i<8;i++)
{
int xx=x+dir[i][0];
int yy=y+dir[i][1];
flag[xx][yy]=true;
}
}
int judge()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(g[i][j]=='#' && flag[i][j]==false)
return 0;
}
}
return 1;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%s",g[i]);
for(int i=1;i<n-1;i++)
{
for(int j=1;j<m-1;j++)
{
if(check(i,j))
change(i,j);
}
}
if(judge())
printf("YES\n");
else
printf("NO\n");
return 0;
}
C. Sequence Transformation
input
standard input
output
standard output
Let's call the following process a transformation of a sequence of length nn.
If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of nn integers: the greatest common divisors of all the elements in the sequence before each deletion.
You are given an integer sequence 1,2,…,n1,2,…,n. Find the lexicographically maximum result of its transformation.
A sequence a1,a2,…,ana1,a2,…,an is lexicographically larger than a sequence b1,b2,…,bnb1,b2,…,bn, if there is an index ii such that aj=bjaj=bj for all j<ij<i, and ai>biai>bi.
Input
The first and only line of input contains one integer nn (1≤n≤1061≤n≤106).
Output
Output nn integers — the lexicographically maximum result of the transformation.
Examples
input
3
output
1 1 3
input
2
output
1 2
input
1
output
1
Note
In the first sample the answer may be achieved this way:
- Append GCD(1,2,3)=1(1,2,3)=1, remove 22.
- Append GCD(1,3)=1(1,3)=1, remove 11.
- Append GCD(3)=3(3)=3, remove 33.
We get the sequence [1,1,3][1,1,3] as the result.
题意:给定一个数字,找从1到n这n个数字的最大公约数,然后从这n个数字中去掉一个数字,使得去掉之后剩下的n-1个数字的最大公约数能比之前的大,每次都去掉一个数字,使得最大公约数能够最快的上升。
找规律:
特殊情况 n=3的时候,特意输出一下就好了。
奇数的情况下是在偶数的情况下转化的。
偶数的情况下,要判断是不是2的次幂,是2的次幂的时候,可能就要再多加数字。
举例: n=4
1.从 1 2 3 4 中找最大公约数 ------>1
2.去掉1之后,从2 3 4 中找最大公约数 ------->1
3.去掉3之后,从2 4 中找最大公约数 -------->2
4.去掉2之后,从4中找最大公约数 -------->4
所以最后输出 1 1 2 4 ------>这个序列是按照字典序上升最快的序列。
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=1000100;
int n,ans=1;
int main()
{
scanf("%d",&n);
while(n)
{
if(n==3)
{
printf("%d %d %d\n",ans,ans,ans*3);
break;
}
else
{
for(int i=0;i<(n+1)/2;i++)
printf("%d ",ans);
}
n=n/2;
ans=ans*2;
}
return 0;
}
D. Nature Reserve
题意明确
算法用的是三分,对代码还不是很明确
暂且把代码放在这里吧!
#include<bits/stdc++.h>
using namespace std;
#define ld long double
// from_luogu
int n;
int x[300001],y[300001];
ld chk(ld X){
ld A=0;
for(int i=1;i<=n;i++)
A=max(A,((x[i]-X)*(x[i]-X)+(ld)y[i]*y[i])/((ld)2*y[i]));
return A;
}
int main(){
int Mx=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",x+i,y+i);
if(y[1]<0)
for(int i=1;i<=n;i++)
y[i]=-y[i];
for(int i=1;i<=n;i++)
if(y[i]<0)
return puts("-1"),0;
ld l=-1.1e7, r=1.1e7, mid1, mid2;
for(int i=1;i<=100;i++){
mid1=(l+l+r)/3, mid2=(l+r+r)/3;
ld a1=chk(mid1), a2=chk(mid2);
if(a1>a2) l=mid1;
else r=mid2;
}
printf("%.10lf\n",(double)chk(mid1));
return 0;
}
E. Split the Tree
分裂树,将树拆分成尽可能少的垂直路径,使每条路径包含的顶点不超过L,每条路上的整数wi之和不超过S,每个顶点应该完全属于一条路径。
下面代码有些问题
给出测试样例::
8 8 8
1 1 1 1 1 1 1 1
3 4 5 6 7 8 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string.h>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
const int maxn=1e5+10;
typedef long long int ll;
int a[maxn],fa[maxn],vis[maxn];
int main()
{
ll n,l,s;
cin>>n>>l>>s;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]>s)
{
puts("-1");
return 0;
}
}
memset(fa,0,sizeof(fa));
memset(vis,0,sizeof(vis));
for(int i=2;i<=n;i++)
{
scanf("%d",&fa[i]);
}
int ans=0;
for(int i=n;i>=1;i--)
{
if(!vis[i])
{
int now=i;
int now1=l;
ll nows=s;
ans++;
while(now && now1>0 && nows>=a[now])
{
vis[now]=1;
now1--;
nows-=a[now];
now=fa[now];
}
}
}
printf("%d\n",ans);
return 0;
}