20190922 byte beating, 0925ebay, puzzle

Byte beating

1.

 

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm> 
using namespace std;
#define minn 1e-9
int n;
int ans[1000001];
int main(){
	scanf("%d",&n);
	string str;
	cin>>str;
	//cout<<str;
	vector<int> que;
	for(int i=0;i<n;i++){
		if(str[i]=='O'){
			que.push_back(i);
			ans[i]=0;
		}
		else{
			ans[i]=1;
		}
	}
	//cout<<que.size()<<endl;
	int temp=-1;
	for(int i=0;i<n;i++){
		if(ans[i]==0){
			temp++;
			printf("%d ",ans[i]);
			continue;
		}
		if(i<que[0]){
			ans[i]=que[0]-i;		
		}
		else{
			if(temp==que.size()-1){
				ans[i]=i-que[temp];
			}
			else{
				ans[i]=min(i-que[temp],que[temp+1]-i);
			}
		}
		printf("%d ",ans[i]);
	}
	printf("\n");
	return 0;
}

2.

I feel the idea is right, but it is over 0%, I don’t know what’s going on

 

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue> 
using namespace std;
#define minn 1e-9
int t,n,m;
int a[10001];
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d %d",&n,&m);
		priority_queue<int,vector<int>,less<int> > pq;
		int sum=0;
		int count=0;
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(sum+a[i]<=m){
				pq.push(a[i]);
				sum=sum+a[i];
				if(i==n-1)
				printf("%d",count);
				else
				printf("%d ",count);
			}
			else{
				while(sum+a[i]>m){
					int temp=pq.top();
					pq.pop();
					sum=sum-temp;
					count++;
				}
				pq.push(a[i]);
				sum=sum+a[i];
				if(i==n-1)
				printf("%d",count);
				else
				printf("%d ",count);
			}
			//printf("sum%d \n",sum);
		}
		printf("\n");
	}
	return 0;
}

3.

Topological sort

Too lazy to write

Output -1 over 50%. . .

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue> 
#include<sstream>
using namespace std;
#define minn 1e-9
int main(){
	string line;
	int t;
	while(getline(cin,line)&&line!=""){
		stringstream ss(line);
		int i;
		ss>>i;
		//cout<<i<<endl;
	}
	printf("-1\n");
	return 0;
}

4.

ebay

1.

 Violence 45%

from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
m = int(input().strip())
queries = []
for _ in range(m):
	l, r = map(int, input().strip().split())
	ans = 0
	cnt = Counter(a[l-1:r])
	for key in cnt:
		if cnt[key] == 1:
			ans += 1
	print(ans)

 

from collections import Counter, defaultdict, OrderedDict

def cnt_one(c):
	ans = 0
	for key in c:
		if c[key] == 1:
			ans += 1
	return ans

n = int(input().strip())
a = list(map(int, input().strip().split()))
m = int(input().strip())
queries = defaultdict(list)
res_queries = OrderedDict()
print_queries = []
for _ in range(m):
	l, r = map(int, input().strip().split())
	queries[l].append(r)
	res_queries[(l, r)] = 0
	print_queries.append((l, r))
for key in queries:
	queries[key].sort()
	cnt = Counter()
	l = key
	for r in range(l, queries[key][-1]+1):
		cnt[a[r-1]] += 1
		if (l, r) in res_queries:
			res_queries[(l, r)] = cnt_one(cnt)
for l, r in print_queries:
	print(res_queries[(l, r)])

2.

Puzzle

1.

The first time you catch the second one, if you are not in the second middle school, you will be in the 1st, 3rd, 4th, and 5th middle schools. At night, you can only go to the 2nd,
3rd, 4th and 5th middle schools . At night, I ran to 1st,
3rd, 4th, and 5th . The third time I caught the fourth. If not in 4th, I was in 1st,
3rd , and 5th . At night, I ran to 2nd and 4th. At night
, I went to No. 1 Middle School at night , and the fifth time I caught the third. If I wasn’t in No. 3 middle school, then I was in No. 1 middle school. At night, I ran to No. 2 middle school
.
So it can be caught up to six times


2.

There are only two situations for A and B in archery. The probability of miss is 50%. A and B each 100 times. A cheated. He shot 101 times and asked A’s probability of winning

 

Guess you like

Origin blog.csdn.net/LXQ1071717521/article/details/101995148