哈哈哈哈哈,这场比赛好像有点简单。
写下题解吧:
http://codeforces.com/contest/1036
A:就是一个公式
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
LL n,k;
while(scanf("%lld%lld",&n,&k)!=EOF){
int lala=k%n;
LL ans;
if(lala==0)
ans=k/n;
else
ans=k/n+1;
printf("%lld\n",ans);
}
}
B:这道题比较考验猜想。
B. Diagonal Walking v.2
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Mikhail walks on a Cartesian plane. He starts at the point (0,0)
, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0,0)
, he can go to any of the following points in one move:
- (1,0)
- ;
- (1,1)
- ;
- (0,1)
- ;
- (−1,1)
- ;
- (−1,0)
- ;
- (−1,−1)
- ;
- (0,−1)
- ;
- (1,−1)
- .
If Mikhail goes from the point (x1,y1)
to the point (x2,y2) in one move, and x1≠x2 and y1≠y2
, then such a move is called a diagonal move.
Mikhail has q
queries. For the i-th query Mikhail's target is to go to the point (ni,mi) from the point (0,0) in exactly ki moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point (0,0) to the point (ni,mi) in ki
moves.
Note that Mikhail can visit any point any number of times (even the destination point!).
Input
The first line of the input contains one integer q
(1≤q≤104
) — the number of queries.
Then q
lines follow. The i-th of these q lines contains three integers ni, mi and ki (1≤ni,mi,ki≤1018) — x-coordinate of the destination point of the query, y
-coordinate of the destination point of the query and the number of moves in the query, correspondingly.
Output
Print q
integers. The i-th integer should be equal to -1 if Mikhail cannot go from the point (0,0) to the point (ni,mi) in exactly ki moves described above. Otherwise the i
-th integer should be equal to the the maximum number of diagonal moves among all possible movements.
Example
Input
Copy
3 2 2 3 4 3 7 10 1 9
Output
Copy
1 6 -1
Note
One of the possible answers to the first test case: (0,0)→(1,0)→(1,1)→(2,2)
.
One of the possible answers to the second test case: (0,0)→(0,1)→(1,2)→(0,3)→(1,4)→(2,3)→(3,2)→(4,3)
.
In the third test case Mikhail cannot reach the point (10,1)
in 9 moves.
就是不能从对角线到达的时候,那么就要减1.
否则能从对角线到达的时候就要看多出来的是奇数还是偶数,如果是奇数就要考虑要将对角线的一条边变成横着一条竖着一条的,
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
LL n,a,b,c,ans;
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld%lld%lld",&a,&b,&c);
if(a<b)
swap(a,b);///始终保持a>b
///步数是a
if(c<a)
{
cout<<"-1"<<endl;
}
else{
///int d=c-a;///多出来的
if((a-b)%2==1)
c--;
else if((c-a)%2==1)
c-=2;
cout<<c<<endl;
}
}
return 0;
}
C:
就是简单的合并就行了。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=300000+1000;
LL a[maxn],b[maxn];
int main()
{
int n,m;
while(scanf("%d",&n)!=EOF){
LL sum1=0,sum2=0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum1+=a[i];
}
scanf("%d",&m);
for(int i=1;i<=m;i++){
scanf("%lld",&b[i]);
sum2+=b[i];
}
if(sum1!=sum2)
{puts("-1\n");continue;}
sum1=0;
sum2=0;
int i=1;
int j=1;
int lala=0;
while(1){
sum1=sum2=0;
if(i>=n+1 && j>=m+1)
break;
while(1){
if(sum1==sum2 && sum1!=0)
{
/// cout<<sum1<<endl;
lala++;break;
}
if(sum1>sum2){
sum2+=b[j];
j++;
}
else{
sum1+=a[i];
i++;
}
}
}
cout<<lala<<endl;
}
return 0;
}
D:
就是个简单的数位dp。就是一段区间内数字中非0个数不超过3的个数
套了个模板就出了
代码:
#include<bits/stdc++.h>
typedef long long LL;
const int maxn=50;
int dig[maxn];
LL f[maxn][11][maxn];
LL dfs(int pos,int pre,int num,int limit){
if (pos<0)
{
if(num<=3)
return 1;
else
return 0;
}
if (!limit&&f[pos][pre][num]!=-1)
return f[pos][pre][num];
LL res=0;
int last=limit?dig[pos]:9;
for (int i=0;i<=last;i++){
res+=dfs(pos-1,i,(num+(i==0?0:1)),limit&&(i==last));
}
if (!limit)
f[pos][pre][num]=res;
return res;
}
LL solve(LL n){
int len=0;
while (n){
dig[len++]=n%10;
n/=10;
}
return dfs(len-1,0,0,1);
}
int main()
{
LL n,m;
int t;
scanf("%d",&t);
while(t--){
memset(f,-1,sizeof(f));
scanf("%lld%lld",&n,&m);
LL lala=solve(m)-solve(n-1);
printf("%lld\n",lala);
}
}