Codeforces Round 864 (Div. 2)

Problem - C - Codeforces

思路:

  1. 我们一开始询问两个点(假设n>1)(1,1),(2,1),保持c不变,变r,那么如果两个输入d1==d2,说明c离得远,c坐标就是1+d1
  2. 否则,说明r离得远,那么x坐标就是d1+1,那么再询问一次得到的输入d3,那么y=1+d3
#include 
using namespace std;

int main()
{
	std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		{
			int n,m;
			cin>>n>>m;
			int x=1,y=1;
			cout<<'?'<<' '<>d1;
			if(d1==0)
				{
					cout<<'!'<<' '<=2)
				{
					cout<<'?'<<' '<<1+x<<' '<<1<>d2;
					if(d1==d2)
						{
							y+=d1;
							cout<<'?'<<' '<>d3;
							x+=d3;
							cout<<'!'<<' '<>d3;
							y+=d3;
							cout<<'!'<<' '<

Problem - D - Codeforces

思路:树上大模拟

  1. 我们显然可以先dfs求出每个子树的节点数与val值
  2. 然后考虑交换,我们可以用优先队列存储每个节点的儿子们,交换时提取当前重儿子即可
#include 
using namespace std;
#define ll               long long
#define endl             "\n"
#define int              long long
#define endll            endl< pii;

const int N = 1e5 + 10;
int fa[N],sum[N],a[N],cnt[N];
vectoredge[N];
struct cmp//优先队列排序记得反着来
{
	bool operator()(pii a,pii b)
	{
		if(a.first!=b.first)return a.firstb.second;
	}
};

priority_queue,cmp>son[N];
void dfs(int u,int f)//先建立树
{
	cnt[u]=1;
	fa[u]=f;
	sum[u]=a[u];
	for(auto v:edge[u])
		{
			if(v!=f)
				{
					dfs(v,u);
					sum[u]+=sum[v];
					cnt[u]+=cnt[v];
					son[u].push({cnt[v],v});
				}
		}
}

void mysolve()
{
	int n,m;
	cin>>n>>m;
	for(int i=1; i<=n; ++i)cin>>a[i];
	int x,y;
	for(int i=1; i>x>>y,edge[x].push_back(y),edge[y].push_back(x);
	dfs(1,0);
	int op;
	while(m--)
		{
			cin>>op>>x;
			if(op==1)cout<> t;
	while (t--)
		{
			mysolve();
		}
	system("pause");
	return 0;
}

你可能感兴趣的:(CF杂栏,c++,算法,蓝桥杯)