ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CCF 2015-03

2022-02-28 10:02:58  阅读:187  来源: 互联网

标签:back 03 int 31 cin st ++ 2015 CCF


CCF 历年题目集

A. 图像旋转

按照题目写就行

#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N][N];
int main()
{
	int n,m;
	cin >> n >> m;
	for (int i = 0 ; i < n ; i ++ )
		for (int j = 0 ; j < m ; j ++ )
			cin >> a[i][j];
		
	for (int j = m-1 ; j >= 0 ; j -- )
	{
		for (int i = 0 ; i < n ; i ++ )
		{
			cout << a[i][j] << ' ';
		}
		cout << endl;
	}
	return 0;
}

B. 数字排序

这个随便怎么搞都行,这里我用的结构体的做的

#include <bits/stdc++.h>
using namespace std;
map<int,int> mp;
struct node
{
	int a,b; // a 是数,b 是次数
}st[1005];
int main()
{
	int n;
	cin >> n;

	int x;
	int c=1;
	for (int i = 0 ; i < n ; i ++ )
	{
		cin >> x;
		if(mp[x] != 0) st[mp[x]].b ++ ;
		else
		{	
			mp[x] = c;
			st[c] = {x,1};
			c ++ ;
		}
	}
	sort(st+1,st+1+n,[&](node &a,node &b){
		if(a.b != b.b) return a.b > b.b;
		else return a.a < b.a;
	});
	for (int i = 1 ; i < c ; i ++ ) cout << st[i].a << ' ' << st[i].b << endl;
	return 0;
}

C. 节日

这里将总天数求出来,然后按照规则求解

#include <bits/stdc++.h>
using namespace std;
int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
	int day=0;
	int a,b,c,y1,y2;
	cin >> a >> b >> c >> y1 >> y2;
	for (int i = 1850 ; i <= y2 ; i ++ )
	{
		if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) month[1] = 29;
		else month[1] = 28;
		for (int j = 1 ; j <= 12 ; j ++ )
		{
			if(i >= y1 && j == a)
			{
				int w = (1+day) % 7;
				int cnt = 0;
				for (int d = 1 ; d <= month[j-1] ; d ++ )
				{
					if(w == c - 1) cnt ++ ;
					if(cnt == b) 
					{
						printf("%04d/%02d/%02d\n",i,j,d);
						break;
					}
					w = (w + 1) % 7;
				}
				if(cnt < b) puts("none");
			}
			day += month[j-1];
		}
	}
	return 0;
}

D. 网络延时

该问题可以抽象为求树的直径,注意不能按照题目的编号,因为电脑和交换机编号会重复

#include <bits/stdc++.h>
using namespace std;
const int N = 10010 * 2;

struct Edge
{
	int id,w;
};

vector<Edge> h[N];
int dist[N];

void dfs(int u,int father,int distance)
{
	dist[u] = distance;
	for (int i = 0 ; i < h[u].size() ; i ++ )
	{
		if(h[u][i].id != father)
			dfs(h[u][i].id,u,distance + h[u][i].w);
	}
	return ;
}	

int main()
{
	int n,m;
	cin >> n >> m;

	int a;
	for (int i = 0 ; i < n-1 ; i ++ )
	{
		cin >> a;
		h[i+2].push_back({a,1});
		h[a].push_back({i+2,1});
	}
	for (int i = 1 ; i <= m ; i ++ )
	{
		cin >> a;
		h[i+n].push_back({a,1});
		h[a].push_back({i+n,1});
	}
	dfs(1,-1,0);
	int u = 1;
	for (int i = 1 ; i <= n+m ; i ++ )
		if(dist[u] < dist[i])
			u = i;
	
	dfs(u,-1,0);
	u = 0;
	for (int i = 1 ; i <= n+m ; i ++ )
		if(dist[u] < dist[i])
			u = i;
	
	cout << dist[u] << endl;
	return 0;
}

E. 最小花费

暂时不会~

标签:back,03,int,31,cin,st,++,2015,CCF
来源: https://www.cnblogs.com/Crystar/p/15944365.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有