codeforces #693 (Div. 3)

A

#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int>PII;
const int N=5100;

int main()
{
	int t;cin>>t;
	while(t--)
	{
		int w,h,n;cin>>w>>h>>n;
		int cnt=1;
		while(w%2==0)
		{
			w/=2;
			cnt*=2;
		}
		while(h%2==0)
		{
			h/=2;
			cnt*=2;
		}		
		if(cnt>=n)
			cout<<"YES"<<endl;
		else	
			cout<<"NO"<<endl;
	}
    return 0;
}

B

#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int>PII;
const int N=5100;

int n,a[N];
int main()
{
	int t;cin>>t;
	while(t--)
	{
		cin>>n;
		int cnt1=0,cnt2=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i]&1)
				cnt1++;
			else
				cnt2++; 
		}
		if((cnt1!=0&&cnt1%2==0)||(cnt1==0&&cnt2%2==0))
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
		
		
	}
    return 0;
}

C

模拟是O(N*N) 会T
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int>PII;
const int N=2e5+10;
typedef long long ll;
int n,a[N];
ll f[N];
int main()
{
	int t;cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i],f[i]=0;
		ll ans=-1;
		for(int i=1;i<=n;i++)
		{
			int j=i;
			while(j<=n)
			{
				f[i]+=a[j];
				j+=a[j];
			}
		}
		for(int i=1;i<=n;i++)
			ans=max(ans,f[i]);
		cout<<ans<<endl;
	}
    return 0;
}
优化之后
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int>PII;
const int N=2e5+10;
typedef long long ll;
int n,a[N];
bool st[N];
int main()
{
	int t;cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i],st[i]=0;
		ll ans=-1;
		//注意到第一次跳到某个点一定比第二次跳到同
		//一个点得分高 
		for(int i=1;i<=n;i++)
		{
			ll j=i,sum=0;
			while(j<=n)
			{
				if(st[j])break;
				st[j]=1;
				sum+=a[j];
				j+=a[j];
			}
			ans=max(sum,ans);
		}
		cout<<ans<<endl;
	}
    return 0;
}

D

#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int>PII;
const int N=2e5+10;
typedef long long ll;
int n,a[N];

int main()
{
	int t;cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n,greater<int>());
		ll suma=0,sumb=0;//注意爆ll 
		for(int i=0;i<n;i++)
		{
			if(i&1)
			{
				if(a[i]&1)
					sumb+=a[i];
			}
			else
			{
				if(a[i]%2==0)
					suma+=a[i];
			}
		}
		if(suma>sumb)
			cout<<"Alice"<<endl;
		else if(suma==sumb)
			cout<<"Tie"<<endl;
		else
			cout<<"Bob"<<endl;
		
	}
    return 0;
}

E

https://blog.csdn.net/weixin_43911947/article/details/112217993?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
/*
*/
const int maxn = 2e5 + 10;

struct node{
	int x, y, id;
	bool operator < (const node &a) const{
		if(x == a.x) 
			return y < a.y;	
		return x < a.x;
	}
}a[maxn];
int ans[maxn];
int main(){
	int t, n;
	cin >> t;
	while(t --){
		cin >> n;
		for(int i = 1; i <= n; i ++){
			cin >> a[i].x >> a[i].y;
			if(a[i].x > a[i].y) swap(a[i].x, a[i].y);
			a[i].id = i; ans[i] = -1;
		}
		sort(a + 1, a + n + 1);
		//wi<wj&&hi<hj
		
		for(int i=1;i<=n;i++)
			cout<<a[i].x<<" "<<a[i].y<<" "<<"id="<<a[i].id<<endl;
		 
		int tmp = 0x3f3f3f3f, id = -1, j = 1;
		
		for(int i = 1; i <= n; i ++){
			while(j < i && a[j].x < a[i].x){//排除等于情况 
				if(tmp > a[j].y){//找最小的y 
					tmp = a[j].y;
					id = a[j].id;
				}
				j ++;
			}
			if(tmp < a[i].y) //如果找到了 满足wi<wj&&hi<hj的id,更新id 
				ans[a[i].id] = id;
		}
		
		cout<<"---"<<endl;
				for(int i=1;i<=n;i++)
			cout<<a[i].x<<" "<<a[i].y<<" "<<"id="<<a[i].id<<endl;
		for(int i = 1; i <= n; i ++){
			cout << ans[i]<<" ";
		}
		cout << endl;
	}
	return 0;
}

G

https://blog.csdn.net/qq_44951010/article/details/112311346
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

const int  MAXN=200005;


int d[MAXN], f[MAXN];
bool vis[MAXN];
vector<int> edges[MAXN],c[MAXN];

int main()
{
    int T; scanf("%d", &T);
    while(T--) {
        int n, m; scanf("%d%d", &n, &m);
        for(int i=0;i<=n;++i) edges[i].clear(), c[i].clear();
        //邻接矩阵存图 
        for(int i=0;i<m;++i) {
            int u, v; scanf("%d%d", &u, &v);
            edges[u].push_back(v);
        }
        // 求d,有向图,邻接矩阵求bfs 
        for(int i=0;i<=n;i++) vis[i]=0;
        
        queue<int> Q;
        d[1] = 0; vis[1] = true;
        Q.push(1);
        while(Q.size()){
            int u = Q.front(); Q.pop();
            
            c[d[u]].push_back(u);//与d[u]距离相同的点放一起
//            cout<<u<<"---------";
            for(int i=0;i<edges[u].size();i++) {
                int v = edges[u][i];//v是u的一个临点 
                if(vis[v]) continue;
                d[v] = d[u] + 1;
                vis[v] = true;
                Q.push(v);
            }
        }
        
//        for(int i=0;i<3;i++)
//        {
//        	for(int j=0;j<c[i].size();j++)
//        		cout<<c[i][j]<<" ";
//        	cout<<endl;
//		}
        	
				
        cout<<endl;
//        for(int i=1;i<=n;i++)
//        	cout<<d[i]<<" ";
//		cout<<endl; 
        
        // 求结果f
        // d 0 1 1 2 2 2
        // f 0 0 1 2 0 1
        //f一定会被d所更新 
        for(int i=1;i<=n;++i) f[i] = d[i];  // f初值等于d
        
        for(int l=n-1;l>0;l--) {// 由远到近遍历每一点 
            int num = c[l].size();
            for(int i=0;i<num;++i) {
                int u = c[l][i];//点的编号 
                
                int len = edges[u].size();
                
                for(int j=0;j<edges[u].size();++j) {
                    int v = edges[u][j];
                    //遍历这些点 
                    //if(d[u] < d[v]) f[u] = min(f[u], f[v]);
                    f[u] = min(f[u], f[v]);
//                    else f[u] = min(f[u], d[v]);
                }
            }
        }
        
        for(int i=1;i<=n;++i) printf("%d ", f[i]);
        printf("\n");
    }
    return 0;
}

posted @ 2021-01-13 16:00  30天CF上蓝!!!  阅读(78)  评论(0编辑  收藏  举报