zoukankan      html  css  js  c++  java
  • [暴力题解&&考试反思] 双十一欢乐赛(联赛膜你测试32)

    前言:

    今天考试很迷糊。从7点考到11点半,我大概从7点睡到9点。隐隐约约看到旁边的狗哥敲了好几个题,我才开始写代码。然后因为还是很困,而且T1迷迷糊糊调了好长时间,T3T4的暴力就懒的写了。。。
    估分120,实际得分120。

    暴力写法如下:

    T1 循环依赖

    一眼的sb题,然而读入稍有毒瘤。本来以为每个测试点100组数据会很卡时间,于是卡了很长时间的常。然而最后数据并没有卡,差评。

    代码:
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long llu;
    const int maxn=100000+10,maxm=30000+10;
    const llu base=233;
    llu ha[maxn];
    struct node{
    	llu data;
    	int id;
    	int belong;
    }b[maxn];
    struct Node{
    	int to,nxt;
    }edge[maxn];
    int head[maxm],vis[maxn],dfn[maxn],low[maxn],Stack[maxn];
    int n,tool,cnt,tot,top,tim,Time,cnt_scc;
    bool flag;
    int read(){
    	int w=0,x=1;
    	char ch=getchar();
    	while(ch>'9'||ch<'0'){
    		if(ch=='-') x=-1;
    		ch=getchar();
    	}
    	while(ch<='9'&&ch>='0'){
    		w=(w<<1)+(w<<3)+(ch^48);
    		ch=getchar();
    	}
    	return w*x;
    }
    void add(int from,int to){
    	edge[++cnt].to=to;
    	edge[cnt].nxt=head[from];
    	head[from]=cnt;
    }
    bool cmp(llu x,llu y){
    	return x<y;
    }
    void Init(){
    	n=read();
    	top=tool=Time=cnt_scc=cnt=0;
    	for(int i=1;i<=n;++i){
    		char ch=getchar();
    		while((ch>='A'&&ch<='Z')||(ch>='0'&&ch<='9')||ch==' '){
    			tool++;
    			while((ch>='A'&&ch<='Z')||(ch>='0'&&ch<='9')){
    				b[tool].data=b[tool].data*base+ch;
    				ch=getchar();
    			}
    			b[tool].belong=i;
    			if(ch==' '){
    				ch=getchar();
    				continue;
    			}
    		}
    	}
    	for(int i=1;i<=tool;++i) ha[i]=b[i].data;
    	sort(ha+1,ha+tool+1,cmp);
    	tot=unique(ha+1,ha+tool+1)-ha-1;
    	for(int i=1;i<=tool;++i) b[i].id=lower_bound(ha+1,ha+tot+1,b[i].data)-ha;
    	int xx;
    	for(int i=1;i<=tool;++i){
    		if(b[i].belong!=b[i-1].belong){
    			xx=b[i].id;
    			continue;
    		}
    		if(xx==b[i].id){
    			printf("Yes
    ");
    			flag=1;
    			return;
    		}
    		add(b[i].id,xx);
    	}
    }
    void Clear(){
    	memset(Stack,0,sizeof(Stack));
    	for(int i=1;i<=tot;++i) head[i]=0;
    	for(int i=1;i<=tool;++i) b[i].data=0;
    	for(int i=1;i<=tot;++i) dfn[i]=low[i]=0;
    }
    void tarjan(int u){
    	if(dfn[u]) return;
    	Stack[++top]=u;
    	vis[u]=tim;
    	dfn[u]=low[u]=++Time;
    	for(int i=head[u];i;i=edge[i].nxt){
    		int v=edge[i].to;
    		if(!dfn[v]){
    			tarjan(v);
    			low[u]=min(low[u],low[v]);
    		}else if(vis[v]==tim) low[u]=min(low[u],dfn[v]);
    	}
    	if(dfn[u]==low[u]){
    		cnt_scc++;
    		while(Stack[top+1]!=u){
    			int t=Stack[top];
    			vis[t]=0;
    			top--;
    		}
    	}
    }
    void Solve1(){
    	tim++;
    	for(int i=1;i<=tot;++i) tarjan(i);
    	if(cnt_scc!=tot) printf("Yes
    ");
    	else printf("No
    ");
    }
    void Solve(){
    	int T=read();
    	while(T--){
    		flag=0;
    		Init();
    		if(!flag) Solve1();
    		Clear();
    	}
    }
    int main(){
    	freopen("dependency.in","r",stdin);
    	freopen("dependency.out","w",stdout);
    	Solve();
    	return 0;
    }
    
    

    T2 A

    这个20分也很简单。。暴力跑就行吧?
    我其实是冲着40分去的,因为显然x的值域比询问小,所以排个序就行。。。然而貌似还是会T。
    这个。。反正20分还是没啥问题。

    代码:
    
    
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=500000+10;
    struct F{
    	int a,b;
    }b[maxn];
    int n,q;
    struct Q{
    	int data,id;
    }c[maxn];
    ll res[maxn];
    int read(){
    	int w=0,x=1;
    	char ch=getchar();
    	while(ch>'9'||ch<'0'){
    		if(ch=='-') x=-1;
    		ch=getchar();
    	}
    	while(ch<='9'&&ch>='0'){
    		w=(w<<1)+(w<<3)+(ch^48);
    		ch=getchar();
    	}
    	return w*x;
    }
    bool cmp(Q x,Q y){
    	return x.data<y.data;
    }
    ll suan(int x){
    	ll res=-0x3f3f3f3f3f3f3f3f;
    	for(register int i=1;i<=n;++i) res=max(res,1ll*b[i].a*x*x+b[i].b*x);
    	return res;
    }
    void Solve(){
    	n=read();
    	q=read();
    	for(register int i=1;i<=n;++i){
    		b[i].a=read();
    		b[i].b=read();
    	}
    	for(register int i=1;i<=q;++i){
    		c[i].data=read();
    		c[i].id=i;
    	}
    	sort(c+1,c+q+1,cmp);
    	int last=1000000;
    	ll ans=0;
    	for(register int i=1;i<=q;++i){
    		if(c[i].data!=last){
    			last=c[i].data;
    			ans=suan(c[i].data);
    		}
    		res[c[i].id]=ans;
    	}
    	for(register int i=1;i<=q;++i) printf("%lld
    ",res[i]);
    }
    int main(){
    	freopen("A.in","r",stdin);
    	freopen("A.out","w",stdout);
    	Solve();
    	return 0;
    }
    
    

    T3 B

    emmm...这题的暴力。。。感觉反正硬爆搜肯定没分吧,然后部分分就是推柿子?那和正解有啥区别
    感觉总之就是期望的线性性,整个dp吧

  • 相关阅读:
    VS2015 C#取消最大化按钮,设置鼠标不可调整窗体大小
    C++调用C#编写的DLL【转】
    C#封装成DLL,并在C#中调用
    ubuntu永久修改主机名
    Anaconda3的安装和汉化
    windows下面安装Python和pip教程
    pip install bs4安装失败
    Sublime text 3中文汉化教程
    Vmware安装ubuntu详细教程
    Sublime text3修改tab键为缩进为四个空格
  • 原文地址:https://www.cnblogs.com/wwcdcpyscc/p/13960004.html
Copyright © 2011-2022 走看看