Summer training round2 #9(Training28)
A:签到题
C:模拟搜索题
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<queue>
#define EPS 1.0e-9
#define PI acos(-1.0)
#define INF 30000000
#define MOD 1000000007
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define pai pair<int,int>
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=;
int year[];
int where[];
int visit[];
vector<int> manager[];
int anser=;
void dfs(int x)
{
visit[x]=;
int len=manager[x].size();
for(int i=;i<len;i++)
{
int to=manager[x][i];
if(!visit[to])
{
anser=min(anser,year[to]);
dfs(to);
}
}
}
int main()
{
for(int i=;i<=;i++)
where[i]=i;
int n,m,I;
int from,to;
cin >> n >>m >>I;
for(int i=;i<=n;i++)
cin >>year[i];
for(int i=;i<=m;i++)
{
scanf("%d %d",&from,&to);
manager[to].pb(from);
}
string a;
int cnt;
for(int i=;i<=I;i++)
{
cin >> a;
if(a[]=='T')
{
cin >> from >>to;
swap(where[from],where[to]);
swap(year[where[from]],year[where[to]]);
}
else if(a[]=='P')
{
mem(visit,);
cin >> from;
anser=;
dfs(where[from]);
if(anser==)
cout<<"*"<<endl;
else
cout<<anser<<endl;
}
}
}
D:队友
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
#define INF 2139062143
#define inf -2139062144
#define ll long long
#include<vector>
using namespace std;
map<vector<int> , int> ma;
vector<int> rr;
bool jj = false;
vector<int> fold(int p,vector<int> qq) {
int l = qq.size();
vector<int> re;
for(int i=; i<=l; i++) {
int tt = ;
bool flag = false;
if(p - i >= ) {
tt+=qq[p-i];
flag = true;
}
if(p + i - < l) {
tt+=qq[p + i - ];
flag = true;
}
if(flag) re.insert(re.begin(),tt);
}
return re;
}
void dfs(vector<int> qq) {
int llen = qq.size();
int i,j;
for(i=; i<=llen && jj == false; i++) {
vector<int> tem = fold(i,qq);
if(tem == rr) {
jj = true;
break;
}
if(ma[tem] == ) {
ma[tem] = ;
dfs(tem);
}
}
}
int main() {
vector<int> q;
int n,i,j;
scanf("%d",&n);
for(i=; i<n; i++) {
int a;
scanf("%d",&a);
q.push_back(a);
}
int m;
scanf("%d",&m);
for(i=; i<m; i++) {
int a;
scanf("%d",&a);
rr.push_back(a);
}
dfs(q);
// for(i=0; i<=n; i++) {
// vector<int> tem = fold(i);
// for(j=0; j<tem.size(); j++) {
// printf("%d ",tem[j]);
// }
// printf("\n");
// if(tem == rr) {
// jj = true;
// break;
// }
// }
if(jj) printf("S\n");
else printf("N\n");
return ;
}
E:水题
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<queue>
#define EPS 1.0e-9
#define PI acos(-1.0)
#define INF 30000000
#define MOD 1000000007
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define pai pair<int,int>
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=;
int a[];
int visit[];
queue<int> que;
int main()
{
mem(visit,);
int r,n;
cin >>r >> n;
int now;
for(int i=;i<=n;i++)
{
scanf("%d",&now);
visit[now]=;
}
for(int i=;i<=r;i++)
if(!visit[i])
que.push(i);
int len=que.size();
if(len==)
{
cout<<"*"<<endl;
return ;
}
while(!que.empty())
{
cout<<que.front()<<" ";
que.pop();
}
cout<<endl;
}
F:队友
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
#define INF 2139062143
#define inf -2139062144
#define ll long long
using namespace std;
int a[];
int p[];
map<int,int> q;
int main(){
int n,i,j;
scanf("%d",&n);
int sum = ;
for(i=;i<=n;i++){
scanf("%d",&a[i]);
sum += a[i];
p[i] = sum;
q[sum] = ;
// printf("%d ",sum);
}
// printf("\n");
a[] = ;
q[] = ;
p[] = ;
if(sum % != ){
printf("0\n");
return ;
}
int len = sum / ;
int ans = ;
for(i = ;i < n;i++){
// printf("%d %d %d\n",p[i],(p[i] + len) % sum,(p[i] + len * 2) % sum);
if(q[(p[i] + len) % sum] == && q[(p[i] + len * ) % sum] == ){
ans++;
}
}
printf("%d\n",ans/);
return ;
}
G:队友
#include <bits/stdc++.h>
using namespace std;
struct Node {
int val, id;
bool operator < (const Node & rhs) const {
return val < rhs.val;
}
}a[];
int L, C, X[][], cnt_l[], cnt_c[], l[], c[], b[];
int Solve(int * array, int n) {
for(int i = ; i <= n; i++) a[i].val = array[i], a[i].id = i;
sort(a + , a + + n);
for(int i = ; i <= n; i++) b[i] = a[i].id;
int ans = ;
for(int i = ; i <= n ;i++) {
if(b[i] != i) {
for(int j = i; j <= n; j++) {
if(b[j] == i) {
swap(b[j], b[i]);
ans++;
break;
}
}
}
}
return ans;
}
int main() {
scanf("%d%d", &L, &C);
for(int i = ; i <= L; i++) {
for(int j = ; j <= C; j++) {
scanf("%d", &X[i][j]);
}
}
int flag1 = , flag2 = , cnt, sum;
for(int i = ; i <= L; i++) {
cnt_l[(i - ) * C * C + ( + C) * C / ] = ;
//cout << (i - 1) * C * C + (1 + C) * C / 2 << endl;
}
for(int i = ; i <= C; i++) {
cnt_c[i * L + C * (L - ) * L / ] = ;
//cout << i * L + C * (L - 1) * L / 2 << endl;
}
cnt = ;
for(int i = ; i <= L; i++) {
sum = ;
for(int j = ; j <= C; j++) {
sum += X[i][j];
}
//cout << sum << endl;
if(cnt_l[sum]) cnt++;
}
//cout << cnt << endl;
if(cnt == L) flag1 = ;
cnt = ;
for(int j = ; j <= C; j++) {
sum = ;
for(int i = ; i <= L; i++) {
sum += X[i][j];
}
if(cnt_c[sum]) cnt++;
}
if(cnt == C) flag2 = ;
//cout << flag1 << " " << flag2 << endl;
if(flag1 && flag2) {
for(int i = ; i <= L; i++) {
l[i] = X[i][];
}
for(int i = ; i <= C; i++) {
c[i] = X[][i];
}
int ans = ;
ans += Solve(l, L);
ans += Solve(c, C);
printf("%d\n", ans);
}else {
printf("*\n");
}
return ;
}
H:数论题 矩阵快速幂
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define INF 2139062143
#define inf -2139062144
#define ll long long
using namespace std;
ll mod = ;
struct matrix {
ll sizex,sizey;
ll num[][];
};
matrix mul(matrix a,matrix b) {
matrix result;
result.sizex = a.sizex;
result.sizey = b.sizey;
ll i,j,k;
for(i=; i<a.sizex; i++) {
for(j=; j<b.sizey; j++) {
ll sum = ;
for(k=; k<a.sizey; k++) sum+=a.num[i][k]*b.num[k][j] % mod;
result.num[i][j] = sum % mod;
}
}
return result;
} matrix zero(ll size) {
ll i,j;
matrix result;
result.sizex = size;
result.sizey = size;
for(i=; i<size; i++)
for(j=; j<size; j++)
result.num[i][j] = ;
return result;
} matrix eye(ll size) {
matrix result;
result.sizex = size;
result.sizey = size;
result = zero(size);
for(ll i=; i<size; i++) {
result.num[i][i] = ;
}
return result;
} matrix quickmat(matrix a,ll k) {
matrix origin = a;
matrix res;
res = eye(a.sizex);
while(k) {
if (k & ) {
res=mul(res,origin);
}
k>>=;
origin=mul(origin,origin);
}
return res;
} matrix initial(ll *a,ll sizex,ll sizey) {
ll i,j;
matrix result;
result.sizex = sizex;
result.sizey = sizey;
ll count = ;
for(i=; i<sizex; i++)
for(j=; j<sizey; j++)
result.num[i][j] = a[count++];
return result;
} ll all_ele_sum(matrix a) {
ll re = ;
for(ll i = ; i<a.sizex; i++) {
for(ll j = ; j<a.sizey; j++) {
re+=a.num[i][j];
}
}
return re;
} void printmatrix(matrix a) {
for(ll i = ; i<a.sizex; i++) {
for(ll j = ; j<a.sizey; j++) {
printf("%lld ",a.num[i][j]);
}
printf("\n");
}
printf("\n");
}
int main() {
ll n,k,l;
scanf("%lld%lld%lld",&n,&k,&l);
n /= ;
k %= mod;
l %= mod;
ll a[] = {k,l,,};
if(n == ){
printf("%06lld\n",a[]);
return ;
}
ll x2 = (k * k % mod + l) % mod;
if(n == ){
printf("%06lld\n",x2);
return ;
}
matrix temp = initial(a,,);
matrix re = quickmat(temp,n-);
ll ans = (re.num[][] * x2 % mod + re.num[][] * k % mod) % mod;
printf("%06lld\n",ans);
return ;
}
I:类搜 DP
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<queue>
#define EPS 1.0e-9
#define PI acos(-1.0)
#define INF 30000000
#define MOD 1000000007
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define pai pair<int,int>
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=;
int f[maxn];
int n;
int c;
int t1,t2;
int tmax,tmin;
ll ans[maxn];
ll anser;
ll get(int x)
{
if(x>n)
return ;
if(ans[x]!=-)
return ans[x];
ans[x]=<<;
for(int i=x;i<=n;i++)
{
ll cha=f[i]-f[x];
if(cha>tmax)
break;
if(cha<=t1)
ans[x]=min(ans[x],get(i+)+t1);
if(cha<=t2)
ans[x]=min(ans[x],get(i+)+t2);
}
return ans[x];
}
int main()
{
mem(ans,-);
cin >> n >> c >> t1 >> t2;
tmax=max(t1,t2);
tmin=min(t1,t2);
for(int i=;i<=n;i++)
cin >> f[i];
sort(f+,f++n);
ll anser=get();
cout<<anser<<endl;
}
J:LCA/LCT
#include <bits/stdc++.h>
#define MAXN 20005
#define MAXM 100005
#define inf 0x3f3f3f3f
using namespace std; int n, m, s;
int head[MAXN], cnt;
int fa[MAXN];
int ancient[MAXN][], minw[MAXN][], dep[MAXN]; struct Node {
int u, v, w;
bool operator<(const Node &rhs) const {
return w > rhs.w;
}
} ori_edge[MAXM]; struct Edge {
int to, nxt, w;
} edge[MAXM * ]; int Find(int x) {
return fa[x] == x ? x : fa[x] = Find(fa[x]);
} void AddEdge(int u, int v, int w) {
edge[cnt].to = v;
edge[cnt].w = w;
edge[cnt].nxt = head[u];
head[u] = cnt++;
} void Add(int u, int v, int w) {
AddEdge(u, v, w);
AddEdge(v, u, w);
} void Init() {
memset(head, -, sizeof(head));
cnt = ;
for (int i = ; i <= n; i++) fa[i] = i;
} void Kruskal() {
sort(ori_edge + , ori_edge + m + );
int cnt = ;
for (int i = ; i <= m; i++) {
int f1 = Find(ori_edge[i].u);
int f2 = Find(ori_edge[i].v);
if (f1 != f2) {
fa[f1] = f2;
Add(ori_edge[i].u, ori_edge[i].v, ori_edge[i].w);
cnt++;
if (cnt == n - ) break;
}
}
} void Dfs(int u, int f, int d) {
fa[u] = f;
dep[u] = d;
for (int i = head[u]; ~i; i = edge[i].nxt) {
int v = edge[i].to;
if (v == f) continue;
minw[v][] = edge[i].w;
Dfs(v, u, d + );
}
} void Pre() {
memset(ancient, -, sizeof(ancient));
for (int i = ; i <= n; i++) {
ancient[i][] = fa[i];
}
minw[][] = inf;
for (int j = ; ( << j) <= n; j++) {
for (int i = ; i <= n; i++) {
if (~ancient[i][j - ]) {
int f = ancient[i][j - ];
ancient[i][j] = ancient[f][j - ];
minw[i][j] = min(minw[i][j - ], minw[f][j - ]);
}
}
}
} int Query(int p, int q) {
if (dep[p] < dep[q]) swap(p, q);
int k = ;
while (( << k) < dep[p]) k++;
int ans = inf;
for (int i = k; i >= ; i--) {
if (~ancient[p][i] && dep[ancient[p][i]] >= dep[q]) {
ans = min(ans, minw[p][i]), p = ancient[p][i];
} } if (p == q) return ans;
for (int i = k; i >= ; i--) {
if (~ancient[p][i] && ancient[p][i] != ancient[q][i]) {
ans = min(ans, minw[p][i]);
p = ancient[p][i];
ans = min(ans, minw[q][i]);
q = ancient[q][i];
}
} if (p != q) {
ans = min(ans, minw[p][]);
ans = min(ans, minw[q][]);
}
return ans;
} int main() {
scanf("%d%d%d", &n, &m, &s);
Init();
for (int i = ; i <= m; i++) {
scanf("%d%d%d", &ori_edge[i].u, &ori_edge[i].v, &ori_edge[i].w);
}
Kruskal();
Dfs(, -, );
Pre();
for (int i = ; i <= s; i++) {
int l, h;
scanf("%d%d", &l, &h);
printf("%d\n", Query(l, h));
}
return ;
}
Summer training round2 #9(Training28)的更多相关文章
- Summer training round2 #3
A!: GTY系列题 B!:莫队加分块 GTY系列题 C!:线段树模拟拓扑排序(把普通的拓扑排序的栈操作改成线段树区间减一,查询区间最右侧的0的位置即可.注意一 ...
- Summer training round2 #1
A:水 B:求两个三角形之间的位置关系:相交 相离 内含 ①用三个点是否在三角形内外判断 计算MA*MB.MB*MC.MC*MA的大小 若这三个值同号,那么在三角形的内部,异号在外部 #incl ...
- Summer training round2 #8(Training26)
A:贪心DFS 先从最远的搜起 如果一个点的value>=2 就ans++ D:并查集 E:大模拟 F:快速幂 #include <bits/stdc++.h> using name ...
- Summer training round2 #10(Training 30)
A:签到题 B!:搜索+DP #include<bits/stdc++.h> #define mp make_pair #define pi pair<int,int> usi ...
- Summer training round2 #7 (Training #23)
A:约瑟夫环 套公式 B:线性筛素数 C:投骰子 概率DP F:有权无向图的生成树(边最大值和最小值只差最小) 直接kruskal G:状压BFS或者双向BFS H:模拟题 I:几何题 J:高斯消元
- Summer training round2 #6 (Training #22)
A:二分答案 如果中位数比目前的大就right=mid-1 else left=mid+1 C!:几何 G:优先队列贪心 #include <bits/stdc++.h> using na ...
- Summer training round2 #5 (Training #21)
A:正着DFS一次处理出每个节点有多少个优先级比他低的(包括自己)作为值v[i] 求A B 再反着DFS求优先级比自己高的求C #include <bits/stdc++.h> #incl ...
- Summer training round2 #4 (Training #20)
A!:UESTC1752 B!:找区间内L到R之间内的数的个数 权值分块加莫队 C!:给你一个哈斯图 去掉其中的几条边 要求输出字典序最大的拓扑排序:线段树模拟拓扑排序 D!:要求你找到最短路树并输 ...
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
随机推荐
- Client Dimensions , offsetHeight , scrollTop 属性详解
http://stackoverflow.com/questions/22675126/what-is-offsetheight-clientheight-scrollheight http://ww ...
- PHP xdebug 断点调试
转载自: https://blog.csdn.net/qq_32631847/article/details/82054011
- 【0.1】mysql版本升级(5.6升级到5.7)
目录 [1].升级操作 [2].mysql 5.6安装(二进制) [3].mysql 5.7安装(二进制) [1].升级操作 核心步骤 [1.1]停止mysql 5.6 [1.2]把环境变量引用到My ...
- GrapeCity Documents for Excel 与 Apache POI 功能对比
GrapeCity Documents for Excel 与 Apache POI 功能对比 GrapeCity Documents for Excel 是什么? GrapeCity Documen ...
- Shell脚本编程(一)
shell 脚本编程(一) 1 . shell 的作用 Shell的作用是解释执行用户的命令,用户输入一条命令,Shell就解释执行一条,这种方式称为交互式(Interactive),Shell还有一 ...
- 注入(Injection)
注入(Injection)是: Java EE提供了注入机制,使您的对象能够获取对资源和其他依赖项的引用,而无需直接实例化它们.通过使用将字段标记为注入点的注释之一来装饰字段或方法,可以在类中声明所需 ...
- Hive 教程(三)-DDL基础
DDL,Hive Data Definition Language,数据定义语言: 通俗理解就是数据库与库表相关的操作,本文总结一下基本方法 hive 数据仓库配置 hive 数据仓库默认位置在 hd ...
- L2-013. 红色警报(并查集+无向图联通分量)
战争中保持各个城市间的连通性非常重要.本题要求你编写一个报警程序,当失去一个城市导致国家被分裂为多个无法连通的区域时,就发出红色警报.注意:若该国本来就不完全连通,是分裂的k个区域,而失去一个城市并不 ...
- CentOS 7系统安装Jenkins
一.jenkins 介绍 Jenkins是一个开源的.可扩展的持续集成.交付.部署(软件/代码> 的编译.打包.部署)基于web界面的平台. 简单说,就是各种项目的"自动化" ...
- leecode刷题(28)-- 二叉树的前序遍历
leecode刷题(28)-- 二叉树的前序遍历 二叉树的前序遍历 给定一个二叉树,返回它的 前序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 思路 ...