Codeforces Round 1009 (Div. 3)

传送门:Dashboard - Codeforces Round 1009 (Div. 3) - Codeforces

A. Draw a Square

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//思路:思维题
ll INF=0x7fffffffffffffff;
const int N=1e5+5,mod=1e9+7;
int inf=0x7fffffff;
ll n,m,q,k;
int he[N],ne[N<<1],to[N<<1],cnt;
void solve(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a==b&&b==c&&c==d?"YES":"NO")<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
    while(t--)solve();
    cout.flush(),system("pause");
    return 0;
}

B. The Third Side

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//思路:思维题
ll INF=0x7fffffffffffffff;
const int N=1e5+5,mod=1e9+7;
int inf=0x7fffffff;
void solve(){
    ll n,ans=0;
    cin>>n;
    for(int i=0,a;i<n;i++){
        cin>>a,ans+=a;
    }
    cout<<ans-(n-1)<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
    while(t--)solve();
    cout.flush(),system("pause");
    return 0;
}

C. XOR and Triangle

#include<bits/stdc++.h>
using namespace std;
//思路:思维题
typedef long long ll;
ll INF=0x7fffffffffffffff;
const int N=1e5+5,mod=1e9+7;
int inf=0x7fffffff;
ll n,m,q,k;
int he[N],ne[N<<1],to[N<<1],cnt;
void solve(){
    int a,b=1,c;
    cin>>a;
    int temp=a/4;
    while(temp>0){
        b=b<<1|1;
        temp>>=1;
    }
    c=a^b;
    if(a+b>c&&a+c>b&&b+c>a){
        cout<<b<<"\n";
    }else{
        cout<<-1<<"\n";
    }
     
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
    while(t--)solve();
    cout.flush(),system("pause");
    return 0;
}

D. Counting Points

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//思路:思维+枚举
ll INF=0x7fffffffffffffff;
const int N=1e5+5,mod=1e9+7;
int inf=0x7fffffff;
ll n,m,q,k;
int he[N],ne[N<<1],to[N<<1],cnt;
void solve(){
    cin>>n>>m;
    vector<ll> x(n),r(n);
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<n;i++)cin>>r[i];
    map<ll,ll> mp;
    for(int i=0;i<n;i++){
        int o=x[i];
        for(ll j=-r[i];j<=r[i];j++){
            mp[o+j]=max(mp[o+j],(ll)sqrt(r[i]*r[i]-j*j));
        }
    }
    ll ans=0;
    for(auto c:mp){
        ans+=c.second*2+1;
    }
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
    while(t--)solve();
    cout.flush(),system("pause");
    return 0;
}

E. Empty Triangle

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//思路:思维题
//从三个方向往中间扩,每个方向扩不超过25次一定能找到答案
ll INF=0x7fffffffffffffff;
const int N=1e5+5,mod=1e9+7;
int inf=0x7fffffff;
ll n,m,q,k;
int he[N],ne[N<<1],to[N<<1],cnt;
int ask(int a,int b,int c){
    cout<<"? "<<a<<" "<<b<<" "<<c<<"\n";
    cout.flush();
    cin>>m;
    return m;
}
void solve(){
    cin>>n;
    int a=1,b=2,c=3;
    for(int i=0;i<25;i++){
        int cur=ask(a,b,c);
        if(cur==0){
            cout<<"! "<<a<<" "<<b<<" "<<c<<"\n";
            cout.flush();
            return;
        }else{
            a=cur;
        }
    }
    a=1,b=2,c=3;
    for(int i=0;i<25;i++){
        int cur=ask(a,b,c);
        if(cur==0){
            cout<<"! "<<a<<" "<<b<<" "<<c<<"\n";
            cout.flush();
            return;
        }else{
            b=cur;
        }
    }
    a=1,b=2,c=3;
    for(int i=0;i<25;i++){
        int cur=ask(a,b,c);
        if(cur==0){
            cout<<"! "<<a<<" "<<b<<" "<<c<<"\n";
            cout.flush();
            return;
        }else{
            c=cur;
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
    while(t--)solve();
    cout.flush(),system("pause");
    return 0;
}

F. Counting Necessary Nodes

#include<bits/stdc++.h>
#define int long long
using namespace std;
//思路:思维+数论
//如果一个的正方形正好可以覆盖4个区间内的小一倍的
//正方形,就可以将答案的数量-3,根据题意,每个单独
//正方形的边界都是2的幂,枚举二的幂作为边界,减去可
//以替代的区间数量即可
const int inf=1e9,N=2e5+5;
const int INF=1e18,mod=1e9+7;
void solve(){
	int l1,r1,l2,r2;
	cin>>l1>>r1>>l2>>r2;
	int ans=(r1-l1)*(r2-l2);
	for(int i=1;i<=20;i++){
		int t=1<<i;
		//左边界向上取整
		int lx=(l1+t-1)/t*t,ly=(l2+t-1)/t*t;
		//右边界向下取整
		int rx=r1/t*t,ry=r2/t*t;
		if(lx>=rx||ly>=ry)break;
		ans-=3*(rx-lx)/t*(ry-ly)/t;
	}
	cout<<ans<<"\n";
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	cin>>t;
	while(t--)solve();
	cout.flush();
	system("pause");
	return 0;
}

G. Game With Triangles: Season 2

#include<bits/stdc++.h>
#define int long long
using namespace std;
//思路:区间dp
//对于一个三角形的两个点l和r,枚举中间第三个点i,状态转移为
//1、当前必须在中间选择一个三角形
//dp[l][r]=max(dp[l][r],dp[l+1][i-1]+dp[i+1][r-1]+a[l]*a[i]*a[r]);
//2、当前不在中间选择三角形
//dp[l][r]=max(dp[l][r],dp[l][i]+d[[i+1][r]]);
const int N=2e5+5,mod=998244353;
const int inf=1e9,INF=1e18;
void solve(){
	int n;cin>>n;
	vector<int> arr(n);
	for(int& c:arr)cin>>c;
	vector<vector<int>> dp(n,vector<int>(n,-1));
	auto dfs=[&](auto& dfs,int l,int r)-> int{
		if(l+2>r){
			return 0;
		}else{
			if(dp[l][r]!=-1)return dp[l][r];
			int ans=0;
			for(int i=l+1;i<r;i++){
				ans=max(ans,dfs(dfs,l+1,i-1)+dfs(dfs,i+1,r-1)+arr[l]*arr[r]*arr[i]);
			}
			for(int i=l;i<r;i++){
				ans=max(ans,dfs(dfs,l,i)+dfs(dfs,i+1,r));
			}
			dp[l][r]=ans;
			return ans;
		}
	};
	cout<<dfs(dfs,0,n-1)<<"\n";
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    int t=1;
	cin>>t;
	while(t--)solve();
	cout.flush(),system("pause");
	return 0;
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值