0624欢乐赛 赛后总结

A题

小车问题

甲、乙两人同时从A地出发要尽快同时赶到B地。出发时A地有一辆小车,可是这辆小车除了驾驶员外只能带一人。已知甲、乙两人的步行速度一样,且小于车的速度。问:怎样利用小车才能使两人尽快同时到达。
 

没什么好说的,一道结论题,注意精度即可,直接上代码:
 

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include <time.h>
using namespace std;
double x,a,b; 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>x>>a>>b;
    double lc=(2*a*x)/(3*a+b);
    cout<<fixed<<setprecision(2)<<lc/a+(x-lc)/b;
}

B题

奶牛分苹果

夏天太热了,所有的奶牛都不想门,所以皇宫中的只奶牛提前采摘了一大堆苹果放到空调房里,约定明天一起平分。这些奶牛都很喜欢他们国家的奶牛公主,所以每只奶牛都想给公主留一些苹果。于是,第一只奶牛悄悄来到空调房,把苹果平均分成份,把剩下的个苹果吃了,然后藏起来一份,最后把剩下的苹果重新合在一起。这些奶牛依次悄悄来到空调房,都做同样的操作,恰好每次都剩下了个苹果。第二天,这些奶牛在空调房聚集,把剩下的苹果 分成分,巧了,还是剩下了个。问原来这些奶牛至少采了多少个苹果。

这题我不会做,打了个暴力,骗了70分

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include <time.h>
using namespace std;
long long i,j,k,n,m;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
	while(1){
    	bool p=true;
    	j=n;
    	k=i;
    	while(j--){
    	    if(k%n!=m){
    	    	p=false;
    	    	break;
			}else k=k/n*(n-1);
		}
		if(k%n!=m) p=false;
		else{
			cout<<i;
			return 0;
		}
    	++i;
    	//cout<<i<<'\n';
	}
}

但是这还不够,看了一下数据范围

0<n,m<9

太水了,直接打表+优化

n=8,m=1 的情况下跑了六分钟

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include <time.h>
using namespace std;
int n,m;
//long long i=1,j,k;
long long f[9]={1,7,79,1021,15621,279931,5764795,134217721};
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    cout<<f[n-1]-(n-1)*(m-1);
	/*while(1){
    	bool p=true;
    	j=n;
    	k=i;
    	while(j--){
    	    if(k%n!=m){
    	    	p=false;
    	    	break;
			}else k=k/n*(n-1);
		}
		if(k%n!=m) p=false;
		else{
			cout<<i;
			return 0;
		}
    	++i;
    	//cout<<i<<'\n';
    }*/
}

C题

称重方案

小C为了试验小X,便为物竞的小X出了一道物理相关的题:现在给出n个质量的砝码,问小X能称出多少种质量的物品,可是总有好事者想要破坏,于是乎,n达到了500,远远超出了小X能够承受的范围,锲而不舍的他决定寻求你们的帮助。 注意:天平有两边,两边均可放。

不会做,应该是dp,前缀和骗了40分

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include <time.h>
using namespace std;
int sum;
int n,x;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++){
    	cin>>x;
    	sum+=x;
	}
	cout<<sum;
}

D题

血色十字军

巫妖王的天灾军团终于卷土重来,血色十字军组织了一支先锋军前往诺森德大陆对抗天灾军团,以及一切沾有亡灵气息的生物。孤立于联盟和部落的血色先锋军很快就遭到了天灾军团的重重包围。现在他们只好将主力聚集起來,以抵抗天灾军团的围剿。可怕的是,他们之中有人感染上了亡灵瘟疫,如果不设法阻止瘟疫的扩散,很快就会遭到灭顶之灾。大领主阿比迪斯已经开始调查瘟疫的源头。原来是血色先锋军的內部出现了叛徒,这个叛徒已经投靠了天灾军团,想要将整个血色先锋军全部转化为天灾军团!
无需惊讶,你就是那个叛徒。在你的行踪败露之前,要尽快完成巫妖王交给你的任务。
军团是一个N行M列的矩阵,每个单元是一个血色先锋军的成员。感染瘟疫的人,每过一个小时,就会向四周扩散瘟疫(上下左右4个方向),直到所有人全部感染上瘟疫。你已经掌握了感染源的位置,任务是算出血色先锋军的领主们感染瘟疫的时间,並且将它报告给巫妖王,以便对血色先锋军进行一轮有针对性的围剿。

题面很复杂,其实就是一个很水的bfs

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include <time.h>
using namespace std;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int gry[1000001][3],N,n,m,a[507][507],M;
bool vis[507][507];
void bfs(int num){
    int l=0,r=N;
    while(l<r){
        l++;
        for(int i=0; i<=3; i++){
            int x=gry[l][0]+dx[i];
            int y=gry[l][1]+dy[i];
            if(x>=1&&x<=n&&y>=1&&y<=m&&vis[x][y]==false){
                r++;
                gry[r][0]=x;
                gry[r][1]=y;
                a[x][y]=gry[r][2]=gry[l][2]+1; 
                vis[x][y]=true; 
            }
        }
    }
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>m>>N>>M;
    for(int i=1; i<=N; i++){
        int x,y;
        cin>>x>>y;
        gry[i][0]=x; 
        gry[i][1]=y;
        vis[x][y]=true;
    }
    bfs(N);
    for(int i=1; i<=M; i++){
    	int x,y;
    	cin>>x>>y;
    	cout<<a[x][y]<<endl;
    } 
    return 0;
}

E题

防晒霜

奶牛们计划着去海滩上享受日光浴。为了避免皮肤被阳光灼伤,所有C(1 <= C <= 2500)头奶牛必须在出门之前在身上抹防晒霜。第i头奶牛适合的最小和最大的SPF值分别为minSPF_i和maxSPF_i(1 <= minSPF_i <= 1,000; minSPF_i <= maxSPF_i <= 1,000)。如果某头奶牛涂的防晒霜的SPF值过小,那么阳光仍然能把她的皮肤灼伤;如果防晒霜的SPF值过大,则会使日光浴与躺在屋里睡觉变得几乎没有差别。

为此,奶牛们准备了一大篮子防晒霜,一共L(1 <= L <= 2500)瓶。第i瓶防晒霜的SPF值为SPF_i(1 <= SPF_i <= 1,000)。瓶子的大小也不一定相同,第i瓶防晒霜可供cover_i头奶牛使用。当然,每头奶牛只能涂某一个瓶子里的防晒霜,而不能把若干个瓶里的混合着用。

请你计算一下,如果使用奶牛们准备的防晒霜,最多有多少奶牛能在不被灼伤的前提下,享受到日光浴的效果?

这题很神奇,贪心+排序就能水过,真是万万没想到

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include <time.h>
using namespace std;
int c,l;
int ans;
struct note{
	int x;
	int y;
}a[2507];
struct node{
	int l;
	int r;
}nn[2507];
bool cmp(node a,node b){
	return a.r<b.r;
}
bool cnp(note a,note b){
	return a.x<b.x;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>c>>l;
	for(int i=1; i<=c; i++) cin>>nn[i].l>>nn[i].r;
    for(int i=1; i<=l; i++) cin>>a[i].x>>a[i].y;
    sort(a+1,a+1+l,cnp);
    sort(nn+1,nn+1+c,cmp);
    for(int j=1; j<=c; j++){
    	for(int i=1; i<=l; i++){
    		if(a[i].x>=nn[j].l&&a[i].x<=nn[j].r&&a[i].y>=1){
        		a[i].y--;
        		ans++;
        		break;
	    	}
		}	
	}
	cout<<ans;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值