整理(五)——习题3

6 篇文章 0 订阅

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 3

output

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 1

output

0
4
2

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值