Codeforces
1、整数移动
题目连接:Problem - 1657A - Codeforces
#include <iostream>
#include <cmath>
using namespace std;
int main()
{ int n,i,j,s;
double a;
cin>>n;
int x[n],y[n];
for(i=0;i<n;i++)
{
cin>>x[i]>>y[i];
}
for(j=0;j<n;j++)
{s=x[j]*x[j]+y[j]*y[j];
a=sqrt(s);
if(int(a)==a&&a!=0)
{cout<<"1"<<endl;}
if(int(a)!=a)
{cout<<"2"<<endl;}
if(a==0)
{cout<<"0"<<endl;}}
return 0;
}
input:
3
8 6
0 0
9 15
output:
1
0
2
2、XY序列
题目链接:Problem - 1657B - Codeforces
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
long long B,x,y;
cin>>n>>B>>x>>y;
long long a=0,sum=0;
for(int i=0;i<n;i++)
{
if(a+x>B) a-=y;
else a+=x;
sum+=a;
}
cout<<sum<<endl;
}
}
input
3 5 100 1 30 7 1000000000 1000000000 1000000000 4 1 7 3output
15 4000000000 -10
3、游戏
题目连接:Problem - 1649A - Codeforces
#include <iostream>
using namespace std;
int t,n,a[101],f,l;
int main() {
cin>>t;
while (t--) {
cin>>n;
for (int i=1;i<=n;i++)
cin>>a[i];
f=1;l=n;
while (f<l&&a[f+1]) f++;
while (l>f&&a[l-1]) l--;
cout<<l-f<<endl;
}
return 0;
}
input
3 2 1 1 5 1 0 1 0 1 4 1 0 1 1output
0 4 2