五一回去导致没有打成第四场
其实也就是浙江省赛,还好不要慌,就是要补的题多了好多
这次我和罗大佬,py,hls一队
切了两个水题,其中还有一个水题因为数据问题交不上去,没错就是c题,但是在cf gym上面显示的是ac(权当自己切了两题吧
A(2089): Bit String Reordering
Time Limit: 1 Sec Memory Limit: 512 Mb Submitted: 50 Solved: 25
Description
You have to reorder a given bit string as specified. The only operation allowed is swapping adjacent bit pairs. Please write a program that calculates the minimum number of swaps required. The initial bit string is simply represented by a sequence of bits, while the target is specified by a run-length code. The run-length code of a bit string is a sequence of the lengths of maximal consecutive sequences of zeros or ones in the bit string. For example, the run-length code of “011100” is “1 3 2”. Note that there are two different bit strings with the same run-length code, one starting with zero and the other starting with one. The target is either of these two. In Sample Input 1, bit string “100101” should be reordered so that its run-length code is “1 3 2”, which means either “100011” or “011100”. At least four swaps are required to obtain “011100”. On the other hand, only one swap is required to make “100011”. Thus, in this example, 1 is the answer.
Input
The input consists of several tests case. For each test, the test case is formatted as follows. NM b1 b2 ...bN p1 p2 ...pM ThefirstlinecontainstwointegersN (1≤N ≤15)andM (1≤M ≤N). Thesecondline specifies the initial bit string by N integers. Each integer bi is either 0 or 1. The third line contains the run-length code, consisting of M integers. Integers p1 through pM represent the lengths of consecutive sequences of zeros or ones in the bit string, from left to right. Here, 1≤pj for1≤j≤M and Mj=1pj =N hold. Itisguaranteedthattheinitialbitstringcanbe reordered into a bit string with its run-length code p1, . . . , pM .
Output
Output the minimum number of swaps required.
Sample Input
6 3 1 0 0 1 0 1 1 3 2 7 2 1 1 1 0 0 0 0 4 3 15 14 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 0 1
Sample Output
1 12 7 0
题意就是有一个长度为n和一个长度为m的串
有如下规则”1100“可以 看成 “22” ,“0011“也可以看成”22“;
题目要求你把长度为n的串转化为长度为m的串
转化方式只能是两个相邻的数字相互交换位置,求最小交换次数
我的解决方法是:将长度为m的串先变成0和1的形式,再与长度为n的串,找到第一个不一样的地方,然后开始搜,得到的最小次数即可
因为变成0和变成1是一样的,所以有两个比较
代码如下
#include<stdio.h> #include<string.h> int n,m; int a[30],b[30],c[30]; int vis[2][30]; int main() { while(scanf("%d%d",&n,&m)!=EOF) { int i,j,k; memset(vis,0,sizeof(vis)); for(i=1; i<=n; i++) { scanf("%d",&a[i]); c[i]=a[i]; } for(i=1; i<=m; i++) scanf("%d",&b[i]); k=1; for(i=1; i<=m; i++) for(j=1; j<=b[i]; j++) { if(i%2) { vis[0][k]=0; vis[1][k]=1; k++; } else { vis[0][k]=1; vis[1][k]=0; k++; } } int t1=0,t2=0; for(i=1; i<=n; i++) { if(a[i]!=vis[0][i]) { j=i+1;//从下一个位置开始搜 while(1) { if(j>n) break; //搜完了退出 t1++; //第一次搜的结果 if(a[j]==vis[0][i]) { int x=a[i]; a[i]=a[j]; a[j]=x; break; } j++; if(j>n) break; } } } for(i=1; i<=n; i++) { if(c[i]!=vis[1][i]) { j=i+1; while(1) { if(j>n)break; t2++; //第二次搜的结果 if(c[j]==vis[1][i]) { int x=c[i]; c[i]=c[j]; c[j]=x; break; } j++; if(j>n)break; } } } int flag1=0,flag2=0; for(i=1; i<=n; i++) if(a[i]!=vis[0][i]) { flag1=1; break; } for(i=1; i<=n; i++) if(c[i]!=vis[1][i]) { flag2=1; break; } if(flag1==0&&flag2==0) { //两边搜都可以得到相同的结果时输出小的结果 if(t1>t2)printf("%d ",t2); else printf("%d ",t1); } else if(flag1&&flag2==0)printf("%d ",t2); else if(flag2&&flag1==0)printf("%d ",t1); } }
还有一个水题等会补,先值班去,这个星期主要就整理博客吧,py大佬太强 了
补C题
C(2091): Shopping
Time Limit: 1 Sec Memory Limit: 512 Mb Submitted: 28 Solved: 0
Description
Your friend will enjoy shopping. She will walk through a mall along a straight street, where N individual shops (numbered from 1 to N) are aligned at regular intervals. Each shop has one door and is located at the one side of the street. The distances between the doors of the adjacent shops are the same length, i.e. a unit length. Starting shopping at the entrance of the mall, she visits shops in order to purchase goods. She has to go to the exit of the mall after shopping. She requires some restrictions on visiting order of shops. Each of the restrictions indicates that she shall visit a shop before visiting another shop. For example, when she wants to buy a nice dress before choosing heels, she shall visit a boutique before visiting a shoe store. When the boutique is farther than the shoe store, she must pass the shoe store before visiting the boutique, and go back to the shoe store after visiting the boutique. If only the order of the visiting shops satisfies all the restrictions, she can visit other shops in any order she likes. Write a program to determine the minimum required walking length for her to move from the entrance to the exit. Assume that the position of the door of the shop numbered k is k units far from the entrance, where the position of the exit is N + 1 units far from the entrance.
Input
The input consists of several tests case. N m c1 d1 ... cm dm For each test, the first line contains two integers N and m, where N (1 ≤ N ≤ 1000) is the number of shops, and m (0 ≤ m ≤ 500) is the number of restrictions. Each of the next m lines contains two integers ci and di (1 ≤ ci < di ≤ N) indicating the i-th restriction on the visiting order, where she must visit the shop numbered ci after she visits the shop numbered di (i = 1, . . . , m). Therearenopairofjandkthatsatisfycj =ck anddj =dk.
Output
Output the minimum required walking length for her to move from the entrance to the exit. You should omit the length of her walk in the insides of shops.
Sample Input
10 3 3 7 8 9 2 5 10 3 8 9 6 7 2 4 10 0 10 6 6 7 4 5 2 5 6 9 3 5 6 8 1000 8 34 6 1000 5 1000 7 1000 8 1000 4 1000 9 1000 1 2
Sample Output
23 19 11 23 2997
题意:有一个商场,,其中有n个商店,各个商店之间的距离为1,你得从入口走到出口,然后你要买东西,不过你买东西得遵循一定的规则
规则是,你买a店子的东西,就必须先去b店子买另一个东西,在店子时间忽略不计(可能这就是程序员买东西的习惯吧(雾))
推样例1: 1 2 3 4 5 6 7 8 9 10
规则(3,7) (8,9) (2,5) 那么走到2的时候要先去5 经过3的时候发现要先去7
所以路线是 0~2~3~5~7~5~3~2~7~8~9~8~9~10~出口
最后是23步,可知我们2~5 3~7其中有重合部分的话就合并,所以这题本质上是一个区间合并问题,然后合并的区间经过 l~r~l~r3倍的
区间长度,最后就可以看出规律来了
代码如下
这个是在网上xjb搜的一个区间合并的代码,有点乱搞的意思0.0
#include <iostream> #include <vector> #include <cstdio> #include <algorithm> using namespace std; typedef vector<pair<int, int> > RangeList; int n, m,start, endd; RangeList cover(const RangeList& intervals) { int left = intervals[0].first, right = intervals[0].second; RangeList result; for (int i = 1; i < intervals.size(); ++i) { // 前面自成一个区间,那么就此分开 if (intervals[i].first > right) { result.push_back(make_pair(left, right)); left = intervals[i].first; right = intervals[i].second; } else if (intervals[i].second > right) { right = intervals[i].second; } } result.push_back(make_pair(left, right)); return result; } int solve(const RangeList& intervals) { int d=0; for (int i = 0; i < intervals.size(); ++i){ d+=(intervals[i].second-intervals[i].first)*3; } d+=intervals[0].first; for(int i=1;i<intervals.size();++i){ d+=(intervals[i].first-intervals[i-1].second); } d+=(n+1-intervals[intervals.size()-1].second); return d; } int main() { while(scanf("%d %d",&n,&m) !=EOF) { if(m==0){ printf("%d ",n+1); continue; }; RangeList intervals; for (int i = 0; i < m; ++i) { scanf("%d %d",&start,&endd); intervals.push_back(make_pair(start, endd)); } sort(intervals.begin(), intervals.end()); RangeList result = cover(intervals); int ans=solve(result); printf("%d ",ans); } return 0; }
这个比较正常
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN=1005; struct node { int s,d; }a[MAXN]; bool cmp(node x,node y) { return x.s<y.s; } int main() { int n,m,t; while(~scanf("%d%d",&n,&m)) { for(int i=0;i<MAXN;i++) a[i].d=a[i].s=0; int cnt=0,res=0,t=0; for(int i=0;i<m;i++) { int tp1,tp2; scanf("%d%d",&tp1,&tp2); if(tp1<tp2) //如果先走小的再走大的就可以忽略 { a[cnt].s=tp1; a[cnt++].d=tp2; } } sort(a,a+cnt,cmp); int l=a[0].s,r=a[0].d; for(int i=1;i<cnt;i++) { if(a[i].s<=r) r=max(r,a[i].d); //区间合并,有交集的区间合并为一个 else { res+=(r-t+2*(r-l)); t=r; l=a[i].s; r=a[i].d; } } res+=(n+1-t+2*(r-l)); printf("%d ",res); } }
感谢py大佬 总算是把D题这个诡异的物理题搞出来了
真的是废掉的大学生 公式看了一遍后都推了半天
题目
2092: Space Golf
Time Limit: 1 Sec Memory Limit: 512 Mb Submitted: 50 Solved: 18 SpecialJudge
Description
You surely have never heard of this new planet surface exploration scheme, as it is being carried out in a project with utmost secrecy. The scheme is expected to cut costs of conventional rover-type mobile explorers considerably, using projected-type equipment nicknamed "observation bullets".
Bullets do not have any active mobile abilities of their own, which is the main reason of their cost-efficiency. Each of the bullets, after being shot out on a launcher given its initial velocity, makes a parabolic trajectory until it touches down. It bounces on the surface and makes another parabolic trajectory. This will be repeated virtually infinitely.
We want each of the bullets to bounce precisely at the respective spot of interest on the planet surface, adjusting its initial velocity. A variety of sensors in the bullet can gather valuable data at this instant of bounce, and send them to the observation base. Although this may sound like a conventional target shooting practice, there are several issues that make the problem more difficult.
- There may be some obstacles between the launcher and the target spot. The obstacles stand upright and are very thin that we can ignore their widths. Once the bullet touches any of the obstacles, we cannot be sure of its trajectory thereafter. So we have to plan launches to avoid these obstacles.
- Launching the bullet almost vertically in a speed high enough, we can easily make it hit the target without touching any of the obstacles, but giving a high initial speed is energy-consuming. Energy is extremely precious in space exploration, and the initial speed of the bullet should be minimized. Making the bullet bounce a number of times may make the bullet reach the target with lower initial speed.
- The bullet should bounce, however, no more than a given number of times. Although the body of the bullet is made strong enough, some of the sensors inside may not stand repetitive shocks. The allowed numbers of bounces vary on the type of the observation bullets.
You are summoned engineering assistance to this project to author a smart program that tells the minimum required initial speed of the bullet to accomplish the mission.
Figure D.1 gives a sketch of a situation, roughly corresponding to the situation of the Sample Input 4 given below.
You can assume the following.
- The atmosphere of the planet is so thin that atmospheric resistance can be ignored.
- The planet is large enough so that its surface can be approximated to be a completely flat plane.
- The gravity acceleration can be approximated to be constant up to the highest points a bullet can reach.
These mean that the bullets fly along a perfect parabolic trajectory.
You can also assume the following.
- The surface of the planet and the bullets are made so hard that bounces can be approximated as elastic collisions. In other words, loss of kinetic energy on bounces can be ignored. As we can also ignore the atmospheric resistance, the velocity of a bullet immediately after a bounce is equal to the velocity immediately after its launch.
- The bullets are made compact enough to ignore their sizes.
- The launcher is also built compact enough to ignore its height.
You, a programming genius, may not be an expert in physics. Let us review basics of rigid-body dynamics.
We will describe here the velocity of the bullet v with its horizontal and vertical components vxand vy (positive meaning upward). The initial velocity has the components vix and viy, that is, immediately after the launch of the bullet, vx = vix and vy = viy hold. We denote the horizontal distance of the bullet from the launcher as x and its altitude as y at time t.
-
The horizontal velocity component of the bullet is kept constant during its flight when atmospheric resistance is ignored. Thus the horizontal distance from the launcher is proportional to the time elapsed.
x=vixt(1)(1)x=vixt
-
The vertical velocity component vy is gradually decelerated by the gravity. With the gravity acceleration of g, the following differential equation holds during the flight.
dvydt=−g(2)(2)dvydt=−g
Solving this with the initial conditions of vy = viy and y = 0 when t = 0, we obtain the following.
y==−12gt2+viyt−(12gt−viy)t(3)(4)(3)y=−12gt2+viyt(4)=−(12gt−viy)t
The equation (4) tells that the bullet reaches the ground again when t = 2viy/g. Thus, the distance of the point of the bounce from the launcher is 2vixviy/g. In other words, to make the bullet fly the distance of l, the two components of the initial velocity should satisfy 2vixviy = lg. -
Eliminating the parameter t from the simultaneous equations above, we obtain the following equation that escribes the parabolic trajectory of the bullet.
y=−(g2v2ix)x2+(viyvix)x(5)(5)y=−(g2vix2)x2+(viyvix)x
For ease of computation, a special unit system is used in this project, according to which the gravity acceleration g of the planet is exactly 1.0.
Input
The input consists of several tests case with the following format.
For each test, the first line contains three integers, d, n, and b. Here, d is the distance from the launcher to the target spot (1 ≤ d ≤ 10000), n is the number of obstacles (1 ≤ n ≤ 10), and b is the maximum number of bounces allowed, not including the bounce at the target spot (0 ≤ b ≤ 15).
Each of the following n lines has two integers. In the k-th line, pk is the position of the k-th obstacle, its distance from the launcher, and hk is its height from the ground level. You can assume that 0 < p1, pk < pk + 1 for k = 1, …, n − 1, and pn < d. You can also assume that 1 ≤ hk ≤ 10000 for k = 1, …, n.
Output
Output the smallest possible initial speed vi that makes the bullet reach the target. The initial speed vi of the bullet is defined as follows.
The output should not contain an error greater than 0.0001.
Sample Input
100 1 0 50 100 10 1 0 4 2 100 4 3 20 10 30 10 40 10 50 10 343 3 2 56 42 190 27 286 34
Sample Output
14.57738 3.16228 7.78175 11.08710
题意:起点与终点的距离为d
再这两点之间有n个柱子,第i个柱子的坐标是(pi,hi)
有一小球从起点以速度v做斜抛运动,环境是理想状况
所以小球做斜抛运动与地面接触没有能量损失,即为弹性碰撞
但是题目要求最多弹b次,并且不能与柱子相碰,求最小的v;
emm根据斜抛运动的规律,每次反弹之前运动的x的距离是一样的
y也是一样的,这个时候最小的v应该是可以恰好通过终点,并且
可以通过高度最高的柱子,有一系列公式推导如下给出
代码如下
#include<cstdio> #include<algorithm> #include<cmath> using namespace std; double x[30],h[30]; double x1[30],h1[30]; const int INF=0x7FFFFFFF; int main() { double d; int n,b; double len,hmax,ans; while(scanf("%lf%d%d",&d,&n,&b) !=EOF) { ans=1.0*INF; for(int i=0; i<n; i++) { scanf("%lf%lf",&x[i],&h[i]); } int flag=1; for(int i=1; i<=b+1; i++) { len=1.0*d/(1.0*i); flag=1; hmax=-1; for(int j=0; j<n; j++) { x1[j]=x[j]; while(x1[j]-len>=0) { x1[j]-=len; } h1[j]=h[j]; if(fabs(x[j])<=1e-5) { flag=0; break; } double temph=len*len*h1[j]/(len-x1[j])/x1[j]/4.0; hmax=max(hmax,temph); } if(flag==0) continue; if(hmax<len/4) ans=min(ans,len); else ans=min(len*len/8/hmax+2*hmax,ans); } printf("%.5f ",sqrt(ans) ); } return 0; }
在此感谢py大佬的帮助
贴上大佬的博客
http://www.cnblogs.com/qldabiaoge/p/9004480.html