2021杭电多校4补题记录

总结

lls不在的第一天,想他
数学我** 你个 **

1001 题意

fx是一个由c,cx,c/x,csinx,ccosx,c/sinx,c/cosx,c^x由加号拼接的函数,对他求前缀和一样的东西得到sx,给你fx,问sx是否收敛

1001 思路

高数下练习题
sx收敛,则fx趋0,由高数知识知这些都不趋0,只有常数C均为0时才成立。

1001 代码
#include<stack>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<deque>
#include<vector>
#include<iostream>
#include<map>
#include<set>
#include<iomanip>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
ll GCD(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int inf=0x3f3f3f3f;
string s;
int T;
bool boo;
signed main() 
{
    #ifndef ONLINE_JUDGE
            freopen("IO\\in.txt","r",stdin);
            freopen("IO\\out.txt","w",stdout);
            clock_t start, end;
            start = clock();
    #endif
    IOS
    cin>>T;
    while (T--)
    {
        cin>>s;
        boo=false;
        for (int i=0;i<s.length();i++)
            if (s[i]>'0'&&s[i]<='9') boo=true;
        if (boo) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }

    #ifndef ONLINE_JUDGE
        end = clock();
        cout << endl << "Runtime: " << (double)(end - start) / CLOCKS_PER_SEC << "s\n";
    #endif
}
1002 题意

一颗树,点带权,aij代表i到j路径上不同点权数,需输出所有aij和一个奇怪东西的乘积加和

1002 思路

可以n²跑,暴力就完事了。

1002 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
//#define double long double
using namespace std;
	typedef long long ll;
	const int maxn=2505;
	const int inf=0x3f3f3f3f;
	const int mod1=1e9+7;
	const int mod2=1e9+9;
	int pow_1[maxn],pow_2[maxn];
	ll pow_m(ll a,ll k,ll p) {
		ll ans=1;
		ll tmp=a%p;
		while(k) {
			if(k&1)ans=ans*tmp%p;
			tmp=tmp*tmp%p;
			k>>=1;
		}
		return ans;
	}
	int n,m,k;
	vector<int>e[maxn];
	int val[maxn];
	unordered_map<int,int>mp;
	int ans1,ans2;
	void dfs(int x,int fa){
		mp[val[x]]++;
		//cout<<"x:"<<x<<"mp:"<<mp.size()<<endl;
		ans1+=(mp.size()*pow_1[x-1])%mod1;
		ans1%=mod1;

		ans2+=(mp.size()*pow_2[x-1])%mod2;
		ans2%=mod2;
		for(auto y:e[x]){
			if(y==fa)	continue;
			dfs(y,x);
		}
		int t=mp[val[x]]-1;
		mp.erase(val[x]);
		if(t)
			mp[val[x]]=t;
	}
	void solve(){
		cin>>n;
		for(int i=1;i<=n;i++)	e[i].clear();
		for(int i=2;i<=n;i++){
			int t;
			cin>>t;
			e[t].push_back(i);
			e[i].push_back(t);
		}
		for(int i=1;i<=n;i++){
			cin>>val[i];
		}
		for(int i=1;i<=n;i++){
			ans1=ans2=0;
			mp.clear();
			//cout<<"i:"<<i<<"------------"<<endl;
			dfs(i,0);
			//cout<<"------------------"<<endl;
			cout<<ans1<<' '<<ans2<<endl;
		}
	}
	signed main(){
        IOS
		#ifndef ONLINE_JUDGE
		    freopen("IO\\in.txt","r",stdin);
		    freopen("IO\\out.txt","w",stdout);
        #endif
		int tn=1;
		cin>>tn;
		for(int i=0;i<2005;i++){
			pow_1[i]=pow_m(19560929,i,mod1);
			pow_2[i]=pow_m(19560929,i,mod2);
		}
		while(tn--){
			solve();
		}
	} 
	
						
1008 题意

11走到nn,只能右走或下走,一些点被挡住了过不去,问有多少点到不了

1008 思路

光球层上的黑子 14:02:49
我们按行看,首先一个性质,一行里能到达的点和不能到达的点是一个交替排列的若干连续段。比如我们用0表示可达,1表示不可达,那么某行的可达情况应当是00001110000这种类型

光球层上的黑子 14:05:40
我们考虑行的转移,在这一行上初始不可达点是输入中的点,对于这样的点,它会阻挡人从左方走过来,对于他右侧的点,只有从上方可达转移下来的点才能到,如果这个点右侧的某个点x上方也是不可达的,那么这个点x一定也不可达。也就是说初始不可达点可以向右“染色”,就是找到右方最远的pos,使得pos上方为1也就是不可达。之后将这一段全部染为1.

光球层上的黑子 14:08:19
染色操作和找操作应当都可以使用数据结构优化成log,至于答案就是每一行1的个数,区间查询就行。空间受限肯定不可能开O(n)棵树,显然当前这一行答案只与上一行答案有关,所以我们开两颗树,类似01背包的空间优化那样滚动着用应该就可以了。

以上为和carry嘴的做法,结果最后嘴完也是我自己写,那没事了…

注意特判一个情况,我们在一开始需要独立找一下上一行最左的0位置,在这个位置左边是到不了的,这也是一直的wa点。

1008 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long
//#define double long double
using namespace std;
	typedef long long ll;
	const int maxn=200505;
	const int inf=0x3f3f3f3f;
	int n,m,k;
    vector<int>point[maxn];
    struct tree{
        int l,r;
        ll sum;
        int add;
    }t1[maxn<<2],t2[maxn<<2];
    ll ans;
    inline void build(int root,int l,int r,tree *t){
        t[root].l=l,t[root].r=r;
        t[root].add=-1;
        if(l==r){
            t[root].sum=0;
            return ;
        }
        int mid=l+r>>1;
        build(root<<1,l,mid,t);
        build(root<<1|1,mid+1,r,t);
        t[root].sum=0;
    }
    inline void pushdown(int root,tree *t){
        if(~t[root].add){
            t[root<<1].sum=(t[root<<1].r-t[root<<1].l+1)*t[root].add;
            t[root<<1|1].sum=(t[root<<1|1].r-t[root<<1|1].l+1)*t[root].add;
            t[root<<1].add=t[root].add;
            t[root<<1|1].add=t[root].add;
            t[root].add=-1;
        }
    }
    void update(int root,int l,int r,int x,tree *t){
        if(l<=t[root].l&&r>=t[root].r){
            t[root].sum=x*(t[root].r-t[root].l+1);
            t[root].add=x;
            return ;
        }
        pushdown(root,t);
        int mid=t[root].l+t[root].r>>1;
        if(mid>=l)   update(root<<1,l,r,x,t);
        if(mid<r)   update(root<<1|1,l,r,x,t);
        t[root].sum=t[root<<1].sum+t[root<<1|1].sum;
    }
    int query(int root,int l,int r,tree *t){
        if(l<=t[root].l&&r>=t[root].r){
            return t[root].sum;
        }
        pushdown(root,t);
        int mid=t[root].l+t[root].r>>1;
		int ans=0;
		if (l<=mid)	ans+=query(root<<1,l,r,t);
		if (r>mid)	ans+=query(root<<1|1,l,r,t);
		return ans;
    }
    int q_pos(int root,int x,tree *t){
        if(x>m) return m+1;
        if(t[root].sum==t[root].r-t[root].l+1)
            return inf;
        if(t[root].l==t[root].r){
            if(t[root].sum==0)  return t[root].l;
            return inf;
        }
        pushdown(root,t);
        int mid=t[root].l+t[root].r>>1;
		int ans=inf;
		if (x<=mid)	ans=min(ans,q_pos(root<<1,x,t));
        if(ans==inf)
		    ans=min(ans,q_pos(root<<1|1,x,t));
		return ans;
    }
    inline void change(int last,int now){
        if(now&1){
            update(1,1,m,0,t2);
            if(now>1){
                int p=q_pos(1,1,t1);
                p=min(p-1,m);
                update(1,1,p,1,t2);
            }
            for(auto x:point[now]){
                int pos=q_pos(1,x+1,t1);
                pos=min(pos-1,m);
                update(1,x,pos,1,t2);
            }
            ans-=query(1,1,m,t2);
        }
        else{
            update(1,1,m,0,t1);
            int p=q_pos(1,1,t2);
            p=min(p-1,m);
            update(1,1,p,1,t1);
            for(auto x:point[now]){
                int pos=q_pos(1,x+1,t2);
                pos=min(pos-1,m);
                update(1,x,pos,1,t1);
            }
            ans-=query(1,1,m,t1);
        }
    }
	void solve(){
        scanf("%d%d%d",&n,&m,&k);
        ans=1ll*n*m;
        for(int i=1;i<=n;i++)   point[i].clear();
        while(k--){
            int a,b;
            scanf("%d%d",&a,&b);
            point[a].emplace_back(b);
        }
        build(1,1,m,t1),build(1,1,m,t2);
        update(1,1,m,1,t1);
        for(int i=1;i<=n;i++){
            change(i-1,i);
        }
        printf("%lld\n",ans);

         /* for(int i=1;i<=m;i++)
            cout<<query(1,i,i,t1)<<' ';
        cout<<endl;
        update(1,5,8,1,t1);update(1,11,12,1,t1);
        for(int i=1;i<=m;i++)
            cout<<query(1,i,i,t1)<<' ';
        cout<<endl;
        cout<<q_sum(1,1,12,t1)<<endl;
        for(int i=1;i<=m;i++)
            cout<<q_pos(1,i,t1)<<' ';
        cout<<endl;  */
       
	}
	signed main(){
		#ifndef ONLINE_JUDGE
		    freopen("IO\\in.txt","r",stdin);
		    freopen("IO\\out.txt","w",stdout);
        #endif
		int tn=1;
        scanf("%d",&tn);
		while(tn--){
			solve();
		}
	} 
	
						
1009 题意

给30*100图,里面6个点阵画,让你输出他们的左右边界。

1009 思路

模拟题,我们二维投影到一维,右侧五个点阵画保证连续,扫一下就行,左侧汉字不一定连续,所以先右扫,再左扫。

1009 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long
//#define double long double
using namespace std;
	typedef long long ll;
	const int maxn=400505;
	const int inf=0x3f3f3f3f;
	int n,m,k;
    int a[105];
	void solve(){
        memset(a,0,sizeof a);
        for(int i=1;i<=30;i++){
            for(int j=1;j<=100;j++){
                char ch;
                cin>>ch;
                if(ch=='#')
                    a[j]++;
            }
        }
        vector<pair<int,int> >v;
        int l,r;
        bool bl=0;
        int p=100;
        while(p&&v.size()<6){
            if(a[p]){
                if(!bl){
                    bl=1;
                    r=p;
                }
            }
            else{
                if(bl){
                    bl=0;
                    l=p;
                    v.push_back({l+1,r});
                }
                bl=0;
            }
            p--;
        }
        for(int i=1;i<=p;i++){
            if(a[i]){
                l=i;
                break;
            }
        }
        for(int i=p;i;i--){
            if(a[i]){
                r=i;
                break;
            }
        }
        v.push_back({l,r});
        reverse(v.begin(),v.end());
        for(auto p:v)
            cout<<p.first<<' '<<p.second<<endl;
	}
	signed main(){
        IOS
		#ifndef ONLINE_JUDGE
		    freopen("IO\\in.txt","r",stdin);
		    freopen("IO\\out.txt","w",stdout);
        #endif
		int tn=1;
		cin>>tn;
		for(int i=1;i<=tn;i++){
            cout<<"Case #"<<i<<":"<<endl;
			solve();
		}
	} 
	
						

未完待续

E 题意
E 思路
E 代码
在这里插入代码片
### 杭电比赛与童年经历 杭电比赛作为国内知名的 ACM/ICPC 训练平台之一,吸引了大量热爱算法的学生参与其中。对于许参赛者来说,这些比赛不仅是技术上的挑战,更是一段难忘的成长历程。 从早期的竞赛启蒙来看,很选手最初接触编程和算法完全是因为兴趣使然[^1]。例如,在中阶段参加 OI 或类似的训练活动时,许人并未意识到其重要性,仅仅将其视为一种娱乐方式。这种轻松的心态反而可能带来意想不到的好成绩,比如某次模拟赛中因团队合作默契而意外夺冠的经历。 当提到杭电比赛的具体题目或经历时,这类赛事通常会设计一系列覆盖广泛知识点的问题来考验参赛者的综合能力。以下是几个典型的例子: #### 题目示例 1. **基础数据结构应用** 这类题目往往考察数组、链表等基本概念的应用场景。 ```cpp // 示例代码:简单的数组遍历求最大值 int findMax(int arr[], int n) { int maxVal = arr[0]; for (int i = 1; i < n; ++i) { if (arr[i] > maxVal) { maxVal = arr[i]; } } return maxVal; } ``` 2. **动态规划入门** 动态规划是 ACM 中非常重要的技巧之一,初学者可以通过经典的背包问题熟悉该方法。 ```python # 背包问题实现 def knapsack(W, wt, val, n): dp = [[0 for _ in range(W + 1)] for __ in range(n + 1)] for i in range(1, n + 1): for w in range(1, W + 1): if wt[i-1] <= w: dp[i][w] = max(dp[i-1][w], dp[i-1][w-wt[i-1]] + val[i-1]) else: dp[i][w] = dp[i-1][w] return dp[n][W] ``` 3. **图论初步探索** 图论相关题目常涉及最短路径计算或者连通性分析等内容。 ```java import java.util.*; public class ShortestPath { static final int INF = Integer.MAX_VALUE / 2; public static void dijkstra(List<List<int[]>> adjList, int start, int[] dist){ PriorityQueue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(a -> a[1])); Arrays.fill(dist, INF); dist[start] = 0; pq.add(new int[]{start, 0}); while(!pq.isEmpty()){ int[] current = pq.poll(); int u = current[0]; if(current[1] > dist[u]) continue; for(int[] edge : adjList.get(u)){ int v = edge[0], weight = edge[1]; if(dist[v] > dist[u] + weight){ dist[v] = dist[u] + weight; pq.add(new int[]{v, dist[v]}); } } } } } ``` 通过上述实例可以看出,无论是童年的简单尝试还是后来深入学习后的复杂解法,每一次练习都为未来打下了坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值