跳到正文

个人记录

8.10上午 河西S班期末综合测试 - 蒋

zmj05130295约 9 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月28日
篇幅
约 9 分钟

版本

  1. v1当前

8.10上午 河西S班期末综合测试 - 蒋

B P3737 [HAOI2014] 遥感监测

对求弦长的公式不熟练,并未求根。

C++
#include <bits/stdc++.h>
using namespace std;
#define gethu(r,y) sqrt(r*r-y*y)
const int N=100,R=50,Xi=1000,Yi=1000;
struct node{
	double l,r;
}p[N+10];
bool cmp(node x,node y){
	return x.r<y.r;
}
int work(){
	int n,r;
	scanf("%d%d",&n,&r);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		double d=gethu(r,y);
		p[i].l=x-d;
		p[i].r=x+d;
		if(p[i].l>p[i].r){
			swap(p[i].l,p[i].r);
		}
	}
	sort(p+1,p+n+1,cmp);
	int nxt=1,ans=1;
	for(int i=2;i<=n;i++){
		if(p[i].l>p[nxt].r){
			ans++;
			nxt=i;
		}
	}
	printf("%d",ans);
	return 0;
}
int main(){
	int T;
	T=1;
	while(T--){
		work();
		printf("\n");
	}
	return 0;
}

C P3405 [USACO16DEC] Cities and States S

写代码时未考虑全面,判断缺少,解题思路未想全就下手去写。

C++
#include <bits/stdc++.h>
using namespace std;
long long read(){
    long long n=0;
    scanf("%lld",&n);
    return n;
}
map<pair<string,string>,int> a;
int main(){
    int n=read(),ans=0;
    for(int i=1;i<=n;i++){
        string s1,s2;
        cin>>s1>>s2;
        string t1=s1.substr(0,2),t2=s2;
        pair<string,string> p1={t1,t2},p2={t2,t1};
        if(t1==t2){
            continue;
        }
        ans+=a[p2];
        a[p1]++;
    }
    printf("%d",ans);
    return 0;
}

F P1671 [USACO05FEB] Rigging the Bovine Election S

对题目样例未解析完整,就着手写题,忽略并不只有一条龙的情况,还有T形等。 对于如何写分支也不清楚,可利用vector存储途径点,遍历下一步时将每个点延伸的情况都遍历。

C++
#include <bits/stdc++.h>
using namespace std;
const int N=5,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int n,a[N+10][N+10];
bool vis[N+10][N+10];
set<vector<pair<int,int> > > f;
void dfs(vector<pair<int,int> > u,int sum){
	if(u.size()>=7){
        //printf("%d ",sum);
		if(sum>0){
            sort(u.begin(),u.end());
            f.insert(u);
        }
		return ;
	}
    int len=u.size();
    for(int j=0;j<len;j++){
        int x=u[j].first,y=u[j].second;
        for(int i=0;i<4;i++){
    		int ix=x+dx[i],iy=y+dy[i];
    		if(ix<1||iy<1||ix>n||iy>n)
    			continue;
    		if(!vis[ix][iy]){
                pair<int,int> p;
                p.first=ix;
                p.second=iy;
                vector<pair<int,int> > v=u;
                v.push_back(p);
    			vis[ix][iy]=true;
    			dfs(v,sum+a[ix][iy]);
    			vis[ix][iy]=false;
    		}
    	}
    }
	return ;
}
int work(){
	n=5;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			char x;
			cin>>x;
			if(x=='H')a[i][j]=-1;
			else a[i][j]=1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
            vector<pair<int,int> > u;
            pair<int,int> p;
            p.first=i;
            p.second=j;
            u.push_back(p);
			vis[i][j]=true;
			dfs(u,a[i][j]);
			vis[i][j]=false;
		}
	}
	printf("%d",f.size());
	return 0;
}
int main(){
	work();
	return 0;
}

G P12194 [NOISG 2025 Prelim] Snacks

抽象化题意,给定nn个数,进行qq次操作,每次将(li,ri)(l_i,r_i)范围内的数更改为xix_i,并输出每次更改前与更改后nn个数的和。 考试时思路已有,写时应注意map的引用规则,注意细节。

C++
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=200000,Q=N,Ai=1000000000;
long long a[N+10];
map<int,int> vis;
signed work(){
	int n,q;
	//scanf("%lld%lld",&n,&q);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		//scanf("%lld",&a[i]);
	}
	long long h=0;
	for(int i=1;i<=n;i++){
		h+=a[i];
	}
	if(q==0){//足足5分哪
		cout<<h;
		//printf("%lld",h);
		return 0;
	}
	cout<<h<<'\n';
	//printf("%lld\n",h);
	/*if(q*n<=100000000){//暴力
		for(int i=1;i<=q;i++){
			int l,r,x;
			cin>>l>>r>>x;
			for(int i=1;i<=n;i++){
				if(a[i]>=l&&a[i]<=r){
					h+=x-a[i];
					a[i]=x;
				}
			}
			printf("%d\n",h);
		}
		return 0;
	}*/
    for(int i=1;i<=n;i++){
		vis[a[i]]++;
	}
	for(int i=1;i<=q;i++){
		int l,r,x;
		cin>>l>>r>>x;
		auto it=vis.lower_bound(l);
		int cnt=0;
		while(it!=vis.end()&&(it->first)<=r){
			int num=it->second;
			//h+=num*(x-(it->first));
    		cnt+=num;
    		h-=num*(it->first);
            auto it2=it;
            it++;
			vis.erase(it2);
		}
        vis[x]+=cnt;
		h+=cnt*x;
		cout<<h<<'\n';
		//printf("%lld\n",h);
	}
//	if(n==6&&q==4){printf("2049\n1848\n1848\n0\n0");return 0;}
//	if(n==5&&q==3){printf("19\n13\n14\n20");return 0;}
//	if(n==6&&q==5){printf("1259\n1263\n3352\n3259\n525\n525");return 0;}
//	printf("0");
	return 0;
}
signed main(){
	work();
	return 0;
}
原文