2021.1.13寒假打卡Day10

今天在水牛客题的时候,碰到了这么一道题:
在这里插入图片描述
原谅下饭如我,当时我就懵了。。。
那么啥叫移位运算呢?我默默打开了
在这里插入图片描述
才知道移位运算符有两个<<>>,属于双目运算符。

  • <<:左移 左边高位舍弃,右边低位补零。若高位没有丢失信息,则<<n效果等同于* pow(2,n)

41883 如下

[空]1010001110011011[空]

41883 << 1 如下

[ 1 ]0100011100110110[空]

得到 18230

  • >>:右移 与左移同理,只是方向相反。

由于移位运算速度很快,所以在程序中遇到乘或除以2n的情况,用他来代替。

好了,题目能做了:

#include<stdio.h>
int main(){
    int n;
    while(scanf("%d",&n)!=EOF)
        printf("%d\n",1<<n);
    return 0;
}

emmmm,只是对我而言简单科普了一下。
进入正题:

Gentle Pairs

Problem Statement
On the xy-plane, We have N points numbered 1 to N. Point i is at (xi,yi), and the x-coordinates of the N points are pairwise different.

Find the number of pairs of integers (i,j) (i<j) that satisfy the following condition:

  • The line passing through Point i and Point j has a slope between −1 and 1 (inclusive).

Constraints
All values in input are integers.
1 ≤ N ≤ 103
|xi|, |yi| ≤ 103
xi ≠ xj for i ≠ j.

Input
Input is given from Standard Input in the following format:
N
x1 y1

xN yN

Output
Print the answer.

Sample Input 1

3
0 0
1 2
2 1

Sample Output 1

2

The slopes of the lines passing through (0,0) and (1,2), passing through (0,0) and (2,1), and passing through (1,2) and (2,1) are 2, 12, and −1, respectively.

Sample Input 2

1
-691 273

Sample Output 2

0

Sample Input 3

10
-31 -35
8 -36
22 64
5 73
-14 8
18 -58
-41 -85
1 -88
-21 -85
-11 82

Sample Output 3

11

说不定暴力出奇迹呢

#include<stdio.h>

int main(){
	int x[1000],y[1000],n,cnt=0;
	scanf("%d",&n);
	if(n==1){printf("0");return 0;}
	for(int i=0;i<n;i++){
		scanf("%d%d",&x[i],&y[i]);
	}
	for(int i=0;i<n-1;i++)
		for(int j=i+1;j<n;j++)
			if((double)(y[j]-y[i])/(double)(x[j]-x[i])>=-1&&(double)(y[j]-y[i])/(double)(x[j]-x[i])<=1)
				++cnt;
	printf("%d",cnt);
	return 0;
}

vjudge又又又上不去了😫
那就看看19级的题吧

Subsequence

A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequence, the sum of which is greater than or equal to S.

Input
The first line is the number of test cases. For each test case the program has to read the numbers N and S, separated by an interval, from the first line. The numbers of the sequence are given in the second line of the test case, separated by intervals. The input will finish with the end of file.

Output
For each the case the program has to print the result on separate line of the output file.if no answer, print 0.

Sample Input

2
10 15
5 1 3 5 10 7 4 9 2 8
5 11
1 2 3 4 5

Sample Output

2
3

尺取法🔗

#include<stdio.h>

int a[100000];

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,s,left=0,right=1,sum=0;
		scanf("%d%d",&n,&s);
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		int cnt=n+1;
		sum+=a[left];
		while(right<n){
			sum+=a[right++];
			while(sum>=s){
				cnt=cnt<right-left+1?cnt:right-left;
				sum-=a[left++];
			}
		}
		if(cnt==n+1)printf("0\n");
		else printf("%d\n",cnt);
	} 
	return 0;
}

Night night ~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值