第一周————ACM刷题初体验

        首先,抱着期待的来到这里,带着疑惑与不解的刷着每天的题目。不是无尽的难题,就是数不清的报错,个人感觉体验下来还OK,就是不太舒服,题目刚开始做还是不太顺手。很多东西甚至都是刚开始接触,例如:我也是头回知道c++里的cin和cout竟然比scanf和printf方便这么多。不过这都是些鸡毛蒜皮的小事,后面这几道”前菜“才是重头戏。

(一)例题

I-Download Manager

Jiajia downloads a lot, a lot more than you can even imagine. Some say that he starts downloading up to 20,000 files together. If 20,000 files try to share a limited bandwidth then it will be a big hazard and no files will be downloaded properly. That is why, he uses a download manager.

If there are T files to download, the download manger uses the following policy while downloading files:

1. The download manager gives the smaller files higher priority, so it starts downloading the smallest n files at startup. If there is a tie, download manager chooses the one with less bytes remaining (for download). We assume that with at least 50 Mega Bytes/sec of bandwidth, n files can be downloaded simultaneously without any problem.

2. The available bandwidth is equally shared by the all the files that are being downloaded. When a file is completely downloaded its bandwidth is instantaneously given to the next file. If there are no more files left except the files that are being downloaded, this bandwidth is immediately shared equally by all remaining files that are being downloaded.

Given the size and completed percentage of each file, your task is to intelligently simulate the behavior of the download manager to find the total time required to download all the files.

Input

The will be at most 10 test cases. Each case begins with three integers T (1 <= T <= 20000), n (1 <= n <= 2000 and 1 <= n <= T) and B (50 <= B <= 1000). Here B denotes the total bandwidth available to Jiajia (In Megabytes/sec). Please note that the download manager always downloads n files in parallel unless there are less than n files available for download. Each of next T lines contains one non-negative floating-point number S (less than 20,000, containing at most 2 digits after the decimal places) and one integer P (0 <= P <= 100). These two numbers denote a file whose size is S megabyte and which has been downloaded exactly P% already. Also note that although theoretically it is not possible that the size of a file or size of its remaining part is a fraction when expressed in bytes, for simplicity please assume that such thing is possible in this problem. The last test case is followed by T=n=B=0, which should not be processed.

Output

For each case, print the case number and the total time required to download all the files, expressed in hours and rounded to 2 digits after the decimal point. Print a blank line after the output of each test case.

Sample

InputcopyOutputcopy
6 3 90
100.00 90
40.40 70
60.30 70
40.40 80
40.40 85
40.40 88
1 1 56
12.34 100
0 0 0
Case 1: 0.66

Case 2: 0.00

Hint

Explanation

In the first sample, there are 6 files and the download manager can download 3 files simultaneously. The size of the smallest file is 40.40 Megabyte but there are
four such files (2nd, 4th, 5th and 6th files). So the download manager chooses the 6th, 5th and 4th files for download as they have less bytes remaining. All these
files get equal bandwidth (30.00 Megabyte/Sec). Of these three files the 8th file is finished first. So instantaneously the 2nd file starts downloading. Then, 5th file
is finished. So the next larger file (3rd file) starts downloading. This process goes on until all files are downloaded.

1.开门见山的说,这题目我以为是类似于多列排队问题,求最长队伍,结果呢,没注意审题。

2.题意大致为给你一些下载好的数据,求剩下数据所下载需要的时间,这么简单吗?对!题目就是如此的简单粗暴,只需要求剩下下载的时间就够了。

3.题解大致为

#include<stdio.h>
int main()
{
	int a,b,c,d,i,j,cnt=1;
	double e;
	while(~scanf("%d%d%d",&a,&b,&c)){
		double sum=0;
		if(a==0&&b==0&&c==0)break;
		for(i=0;i<a;i++){
			scanf("%lf%d",&e,&d);
			sum+=e*(1-d/100.0);
		}
		printf("Case %d: %.2f",cnt,sum/c);cnt++;
	}
	return 0;	
}

4.所以做完这题目之后也算给我刷新了认知观,以为所有的题目都应该是复杂的程序,而没有这么简洁清新的代码。 

A-Together

Problem Statement

You are given an integer sequence of length 𝑁N, 𝑎1,𝑎2,...,𝑎𝑁a1​,a2​,...,aN​.

For each 1≤𝑖≤𝑁1≤i≤N, you have three choices: add 11 to 𝑎𝑖ai​, subtract 11 from 𝑎𝑖ai​ or do nothing.

After these operations, you select an integer 𝑋X and count the number of 𝑖i such that 𝑎𝑖=𝑋ai​=X.

Maximize this count by making optimal choices.

Constraints

  • 1≤𝑁≤1051≤N≤105
  • 0≤𝑎𝑖<105(1≤𝑖≤𝑁)0≤ai​<105(1≤i≤N)
  • 𝑎𝑖ai​ is an integer.

Input

The input is given from Standard Input in the following format:

𝑁N
𝑎1a1​ 𝑎2a2​ .. 𝑎𝑁aN​

Output

Print the maximum possible number of 𝑖i such that 𝑎𝑖=𝑋ai​=X.

Sample 1

InputcopyOutputcopy
7
3 1 4 1 5 9 2
4

For example, turn the sequence into 2,2,3,2,6,9,22,2,3,2,6,9,2 and select 𝑋=2X=2 to obtain 44, the maximum possible count.

Sample 2

InputcopyOutputcopy
10
0 1 2 3 4 5 6 7 8 9
3

Sample 3

InputcopyOutputcopy
1
99999
1

 1.有了前面做题经验后,我发现逻辑是做题的关键,关键在于找到做题的逻辑思路,题目就能迅速的解决掉了。

2.看到这个题目可以用枚举的办法,枚举每次+1、-1或不变的情况,找到最大的一个数就是这道题的答案,简单吧,这种题都是这样,看着复杂,其实想起来也很复杂。

3.题解大致为

#include<stdio.h>
int main(){
	int a,i,c,b[100001]={0};
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&c);
		b[c-1]++;b[c]++;b[c+1]++;
	}
	int max=1;
	for(i=0;i<=100000;i++){
		if(b[i]>max)
			max=b[i];
	}
	printf("%d",max);
}

4.这道题目做完之后,让我知道了我这一辈子学数学的意义,并不一定是为了解决平时算数一类的问题,而是让我们具备强大的逻辑思维来解决生活的方方面面。题目是死的,但是人的脑子是活的。所以,好好学数学吧。

G - 赦免战俘

Background

借助反作弊系统,一些在月赛有抄袭作弊行为的选手被抓出来了!

Description

现有 2𝑛×2𝑛(𝑛≤10)2n×2n(n≤10) 名作弊者站成一个正方形方阵等候 kkksc03 的发落。kkksc03 决定赦免一些作弊者。他将正方形矩阵均分为 4 个更小的正方形矩阵,每个更小的矩阵的边长是原矩阵的一半。其中左上角那一个矩阵的所有作弊者都将得到赦免,剩下 3 个小矩阵中,每一个矩阵继续分为 4 个更小的矩阵,然后通过同样的方式赦免作弊者……直到矩阵无法再分下去为止。所有没有被赦免的作弊者都将被处以棕名处罚。

给出 𝑛n,请输出每名作弊者的命运,其中 0 代表被赦免,1 代表不被赦免。

Input

一个整数 𝑛n。

Output

2𝑛×2𝑛2n×2n 的 01 矩阵,代表每个人是否被赦免。数字之间有一个空格。

Sample 1

InputcopyOutputcopy
3
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 1
0 0 0 0 0 1 0 1
0 0 0 0 1 1 1 1
0 0 0 1 0 0 0 1
0 0 1 1 0 0 1 1
0 1 0 1 0 1 0 1
1 1 1 1 1 1 1 1

 1.第一次看到这种题目,说句实话还是挺高兴的,答案如此简洁明了,但是呢,我不是打印机。发现其中难处时,也算吃了瘪。

2.找最小的n为一时也就是2*2的正方形为递归终止,而每次都减一,减一,减一(重要的事情说三遍)。这题目只需n--不需要n/=2,然后记录左上正方形的位置,easy。

3.题解大致为

#include<bits/stdc++.h>
int a[1025][1025];
int i,j;
void f(int n,int x,int y){
	if(n==1){
		for(i=x;i<x+pow(2,n)/2;i++){
			for(j=y;j<y+pow(2,n)/2;j++)
				a[i][j]=0;
		}
	}
	else{
		f(n-1,x+pow(2,n)/2,y);
		f(n-1,x+pow(2,n)/2,y+pow(2,n)/2);
		f(n-1,x,y+pow(2,n)/2);
		for(i=x;i<x+pow(2,n)/2;i++){
			for(j=y;j<y+pow(2,n)/2;j++)
				a[i][j]=0;
		}
	}
}
int main(){
	int n,t=1;
	scanf("%d",&n);
	for(i=1;i<=pow(2,n);i++){
		for(j=1;j<=pow(2,n);j++){
			a[i][j]=1;
		}
	}
	f(n,t,t);
	int g=pow(2,n);
	for(i=1;i<=pow(2,n);i++){
		for(j=1;j<pow(2,n);j++){
			printf("%d ",a[i][j]);
		}
		printf("%d\n",a[i][g]);
	}
}

 4.代码看起来很长很复杂,其实也就是因为要递归三次,然后多次记录位置的信息,只要知道了递归的条件,这题目也就除了代码长了点罢了。

E - BAN-PICK

 

Description

在第五人格职业联赛的每一场对局中,需要进行 Ban-Pick 流程。Ban 即角色禁用,Pick 即角色选用。

如试题 Winner 所述,游戏分为 求生者(SurvivorSurvivor) 与 **监管者($\texttt
{Hunter})∗∗两个阵营。∗∗求生者阵营∗∗共有)∗∗两个阵营。∗∗求生者阵营∗∗共有n名角色,∗∗监管者阵营∗∗共有名角色,∗∗监管者阵营∗∗共有m$ 名角色。

在某局比赛中,监管者 可以 ban(禁用) 掉 求生者阵营 55 名角色,求生者 可以 ban(禁用) 掉 监管者阵营 22 名角色。

每个角色,无论其属于求生者阵营还是监管者阵营,均可以使用 熟练度 来量化该阵营选手选择该角色的优先程度。选手一定会优先选择 熟练度 更高的角色进行游戏。

基于这样的考量,监管者选手 在进行 Ban 流程时,往往会选择 ban(禁用) 掉 求生者阵营熟练度最高 的若干名 求生者角色。同样,求生者选手 在进行 Ban 流程时,往往会选择 ban(禁用) 掉 监管者阵营熟练度最高 的若干名 监管者角色

在 Ban 流程完成后,需要执行 Pick 流程。

如试题 Winner 所述,求生者选手 需要从 求生者阵营 中选择 44 名不同的角色,监管者选手 需要从 监管者阵营 中选择 11 名角色。

现在告诉你所有角色的名字、阵营与选手对其熟练度,请你给出双方阵营 Pick 的角色名字。

Input

输入共 𝑛+𝑚+1n+m+1 行。

输入的第一行为两个整数 𝑛,𝑚n,m,分别代表求生者阵营角色数和监管者阵营角色数。

接下来 𝑛+𝑚n+m 行,首先为一个仅由英文字母组成的字符串,代表该角色的姓名;接下来为一个大写字符 H 或 S,若为 H,则代表该角色为监管者阵营,若为 S,则代表该角色为求生者阵营;接下来一个正整数,代表该阵营选手对该角色的熟练度。上述字符串、大写字符、正整数之间由一个空格分隔。

Output

输出共 55 行。

输出的第一行为监管者阵营选择角色的角色名。

输出的第二到五行为求生者阵营选择角色的角色名,按照熟练度从高到低排列。

Sample 1

InputcopyOutputcopy
9 3
Amily S 1
Lydia S 2
Lisa S 4
Beck H 1
Freddie S 5
Cliche S 6
Aesop S 7
Eli S 8
Norton S 9
Tiletower H 3
Yidhra H 2
Emma S 3
Beck
Lisa
Emma
Lydia
Amily

Hint

输入输出样例 1 解释

求生者阵营角色:Amily,Lydia,Lisa,Freddie,Cliche,Aesop,Eli,Norton,EmmaAmily,Lydia,Lisa,Freddie,Cliche,Aesop,Eli,Norton,Emma。

监管者阵营角色:Beck,Tiletower,YidhraBeck,Tiletower,Yidhra。

监管者选手将 ban 掉求生者阵营中角色 Norton,Eli,Aesop,Cliche,FreddieNorton,Eli,Aesop,Cliche,Freddie。

求生者选手将 ban 掉监管者阵营中角色 Tiletower,YidhraTiletower,Yidhra。

数据规模与约定

对于前 20%20% 的数据,𝑛=9,𝑚=3n=9,m=3。

对于前 50%50% 的数据,保证 𝑛≤103,𝑚≤103n≤103,m≤103。

对于前 70%70% 的数据,保证 𝑤𝑖≤109wi​≤109。

对于所有数据,保证 9≤𝑛≤105,3≤𝑚≤1059≤n≤105,3≤m≤105,所有名字长度 ≤10≤10。熟练度大小 𝑤𝑖wi​ 满足 1≤𝑤𝑖≤10181≤wi​≤1018。保证每个阵营中熟练度互不相同。保证名字仅有大写字母和小写字母构成。

 1.这题目就得好好阅读题目了,但是为了省时间的话,也可以直接看sample,就大概知道题目要你干啥了。

2.先用结构体存每个角色的名字和熟练度,然后根据H和S分开放,再用sort从大到小排序,这题目就轻轻松松的解决掉了呢!

3.题解大致为

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct tt{
	string a;
	ll c;
}p1[300005],p2[900005];
bool fx2(tt e1,tt e2){
	return e1.c>e2.c;
}
int main(){
	ll n,m,c1=1,c2=1;
	string x1,x2;
	ll x3;
	cin>>n>>m;
	for(int i=1;i<=n+m;i++){
		cin>>x1>>x2>>x3;
		if(x2=="H"){
			p1[c1].a=x1;p1[c1].c=x3;c1++;
		}
		else{
			p2[c2].a=x1;p2[c2].c=x3;c2++;
		}
	}
	sort(p1+1,p1+m+1,fx2);
	sort(p2+1,p2+n+1,fx2);
	cout<<p1[3].a<<endl;
	for(int i=6;i<=9;i++){
		cout<<p2[i].a<<endl;
	}
	return 0;
} 

 4.没啥难度可说,唯一的问题在于要注意熟练度的范围要用long long的类型,其他的按照我上面讲的做就很轻松。

(二)自我感受

1.这个呢没太多好说的,自己既然想来,就是奔着提升自己的目的进发的,刚开始起步肯定没那么轻松。我也看到了很多代码大佬的编程技术和能力,也算是开拓了自己的眼界。有些东西做过之后才知道,这玩意有多不容易。从我刚接触计算机这个圈子的时候我就知道肯定没那么轻松,更何况我本身就不是天赋异禀的选手,只能慢慢磨了,时间肯定很紧,但是只要我肯努力,结果肯定也不会差的。说了这么多废话,其实大致内容也就这么多,其他一些杂七杂八的东西我也不想加进来,感觉对自己的提升不大,举几个例题、说说自己的感受我觉得这一周下来我挺知足的了,至少我是肯定知足了。好吧,该结束了,一切才刚刚开始呢。

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值