gym100676 [小熊骑士限定]2015 ACM Arabella Collegiate Programming Contest
Kuma Rider久违的第二场训练,这场很水,又在vj的榜单上看到第一场的大哥了,2小时ak,大哥牛啤!
A.水
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std;
const double eps = 1e-; int T;
char s[];
int main(void)
{
scanf("%d", &T);
getchar();
while (T--)
{
gets(s);
int len = strlen(s);
int p;
char luo[];
for(int i=;i<=;i++)luo[i]=;
bool fu = false;
int num1 = ;
for (p = ; p < len; p++)
{
//printf("%d %c\n", p, s[p]);
if (s[p] == '-')fu = true;
else if (s[p] >= ''&&s[p] <= '')
{
num1 *= ;
num1 += s[p] - '';
}
else if (s[p] == ' ')continue;
else
{
int tot = ;
while (s[p] != ' ')
{
luo[tot++] = s[p]; p++; }
break;
}
//printf("%d %c\n", p, s[p]);
} if (fu)num1 = -num1;
int num2 = ;
fu = false;
for (p = p + ; p < len; p++)
{
if (s[p] == '-')fu = true;
else if (s[p] >= ''&&s[p] <= '')
{
num2 *= ;
num2 += s[p] - '';
}
}
if (fu)num2 = -num2; if (luo[] == '<')
{
if (luo[] == '=')
{
if (num1 <= num2)printf("true\n");
else printf("false\n");
}
else
{
if (num1 < num2)printf("true\n");
else printf("false\n");
}
}
else if (luo[] == '>')
{
if (luo[] == '=')
{
if (num1 >= num2)printf("true\n");
else printf("false\n");
}
else
{
if (num1 > num2)printf("true\n");
else printf("false\n");
}
}
else if (luo[] == '!')
{
if (num1 != num2)printf("true\n");
else printf("false\n");
}
else
{
if (num1 == num2)printf("true\n");
else printf("false\n");
} } }
B.水
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std;
const double eps = 1e-; int main(void) {
int t;
scanf("%d", &t);
while (t--) {
int a;
int sum = ;
int fla = ;
for (int i = ; i < ; i++) {
scanf("%d", &a);
if (a <= ) fla = ;
sum += a;
}
if (fla || sum != ) printf("NO\n");
else printf("YES\n");
}
return ;
}
C.背包
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std;
const double eps = 1e-;
const int inf = 0x3f3f3f3f; int a[];
int dp[];
int sum;
int main(void) {
int t;
scanf("%d", &t);
while (t--)
{
int K, m, n;
sum = ;
scanf("%d%d%d", &n, &m, &K);
for (int i =; i <= K; i++)
{
scanf("%d", &a[i]);
sum += a[i];
}
int sh = n - sum;
if (m <= sh)printf("0\n");
else
{
int need = m - sh;
memset(dp, inf, sizeof(dp));
dp[] = ;
for (int i = ; i <= K; i++)
{
for (int j = sum; j >= a[i]; j--)
{
dp[j] = min(dp[j - a[i]] + , dp[j]);
}
}
int ans = inf;
for (int i = need; i <= sum; i++)
{
ans = min(ans, dp[i]);
}
printf("%d\n", ans); } }
}
D.判断数独对不对(队友没有用函数,暴力得就很真实)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
//
//int a[105];
//int dp[33768];
//int sum;
//int main(void) {
// int t;
// scanf("%d", &t);
// while (t--)
// {
// int K, m, n;
// sum = 0;
// scanf("%d%d%d", &n, &m, &K);
// for (int i =1; i <= K; i++)
// {
// scanf("%d", &a[i]);
// sum += a[i];
// }
// int sh = n - sum;
// if (m <= sh)printf("0\n");
// else
// {
// int need = m - sh;
// memset(dp, inf, sizeof(dp));
// dp[0] = 0;
// for (int i = 1; i <= K; i++)
// {
// for (int j = need; j >= 0; j--)
// {
// dp[j] = min(dp[j - a[i]] + 1, dp[j]);
// }
// }
// printf("%d\n", dp[need]);
//
// }
//
// }
//}
// char ch[][];
int vis[];
int main(void) {
int t;
scanf("%d", &t);
while (t--) {
getchar();
int fla = ;
for (int i = ; i <= ; i++) {
scanf("%s", ch[i]+);
}
for (int i = ; i <= ; i++) {
memset(vis, , sizeof(vis));
int sum = ;
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
if (sum != ) fla = ;
}
for (int i = ; i <= ; i++) {
memset(vis, , sizeof(vis));
int sum = ;
for (int j = ; j <= ; j++) {
if (!vis[ch[j][i] - '']) {
vis[ch[j][i] - ''] = ;
sum++;
}
}
if (sum != ) fla = ;
}
int sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <=; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
sum = ;
memset(vis, , sizeof(vis));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (!vis[ch[i][j] - '']) {
vis[ch[i][j] - ''] = ;
sum++;
}
}
}
if (sum != ) fla = ;
if (fla) printf("Invalid\n");
else {
printf("Valid\n");
}
}
}
E.树状数组
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std; const int maxn = ;
int c[maxn], a[maxn];
int n;
int lowbit(int x) {
return x&(-x);
}
void update_onepos(int pos, int x) {
while (pos <= n) {
c[pos] += x;
pos += lowbit(pos);
}
}
int getsum_onepos(int pos) {
int sum = ;
while (pos > ) {
sum += c[pos];
pos -= lowbit(pos);
}
return sum;
}
int getsum_range(int x1, int x2) {
return getsum_onepos(x2) - getsum_onepos(x1-);
}
int ax[];
int main(void) {
int t;
scanf("%d", &t);
while (t--) {
int nn;
n = -;
scanf("%d", &nn);
memset(c, , sizeof(c));
for (int i = ; i < nn; i++) {
scanf("%d", &ax[i]);
n = max(ax[i], n);
}
n += ;
for (int i = ; i < nn; i++) {
update_onepos(ax[i], );
}
int sum = ;
for (int i = ; i < nn; i++) {
sum += getsum_range(max(, ax[i] - ), ax[i])-;
sum += getsum_range(ax[i] + , ax[i] + );
}
printf("%d\n", sum / );
}
return ;
}
F.并查集,最后统计根节点的问号数量
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std;
typedef long long LL;
const int maxv = ;
const LL mod = 1e9 + ; int T, n, m;
char s[maxv];
bool hav ;
struct Node
{
int pos;
int fa;
char ch;
}tree[]; int find(int nx)
{
if (tree[nx].fa == nx)return nx; int ff = find(tree[nx].fa);
tree[nx].ch = tree[ff].ch;
return tree[nx].fa=ff;
} bool vis[]; void init()
{
hav = false;
scanf("%d %d", &n, &m);
scanf("%s", s + );
for (int i = ; i <= n; i++)
{
if (s[i] == '?')hav = true;
tree[i].fa = i;
tree[i].ch = s[i];
tree[i].pos = i;
vis[i] = false;
}
} int main(void)
{
scanf("%d", &T);
while (T--)
{
init();
bool can = true; for (int i = ; i <= m; i++)
{
int u, v;
scanf("%d %d", &u, &v);
int fx = find(u), fy = find(v);
if (fx != fy)
{
//printf("%d %d\n", fx, fy);
if (tree[fx].ch!='?'&&tree[fy].ch!='?')
{
if (tree[fx].ch != tree[fy].ch)can = false;
}
else if (tree[fx].ch == '?'&&tree[fy].ch != '?')
{
tree[fx].fa = fy;
tree[fx].ch = tree[fy].ch;
}
else if (tree[fx].ch != '?'&&tree[fy].ch == '?')
{
tree[fy].fa = fx;
tree[fy].ch = tree[fx].ch;
}
else
{
tree[fx].fa = fy;
tree[fx].ch = tree[fy].ch;
}
}
} int l = , r = n;
while (l <= r)
{
int fx = find(l), fy = find(r);
if (fx != fy)
{
//printf("%d %d\n", fx, fy);
if (tree[fx].ch != '?'&&tree[fy].ch != '?')
{
if (tree[fx].ch != tree[fy].ch)can = false;
}
else if (tree[fx].ch == '?'&&tree[fy].ch != '?')
{
tree[fx].fa = fy;
tree[fx].ch = tree[fy].ch;
}
else if (tree[fx].ch != '?'&&tree[fy].ch == '?')
{
tree[fy].fa = fx;
tree[fy].ch = tree[fx].ch;
}
else
{
tree[fx].fa = fy;
tree[fx].ch = tree[fy].ch;
}
}
l++, r--;
} if (!can){printf("0\n"); continue;} for (int i = ; i <= n; i++)
{
int fx = find(i);
s[i] = tree[fx].ch;
} //printf("%s\n", s + 1); LL ans = ;
bool tag = true; for (int i = ; i <= n; i++)
{
int fx = find(i);
if (!vis[fx])
{
if (tree[fx].ch == '?')
{
ans *= ;
ans %= mod;
}
vis[fx] = true;
}
} if (tag)
{
if (hav&&ans == )printf("1\n");
else if(!hav)printf("0\n");
else printf("%lld\n", ans);
}
else printf("0\n"); }
return ;
}
G.状压dp
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<functional>
#include<vector>
using namespace std;
const int maxv = ; int T, n, m;
string s;
map<string, int>mp;
int in[maxv], w[maxv];
int dp[ << ]; int main()
{
cin >> T;
while (T--)
{
cin >> n >> m;
memset(dp, -, sizeof(dp));
getchar();
for (int i = ; i <= n; i++)
{
in[i] = ;
w[i] = ;
}
mp.clear();
for (int i = ; i < n; i++)
{
getline(cin, s);
int pos = -;
for (int j = ; j < s.size(); j++)
{
if (s[j] <= ''&&s[j] >= '')
{
pos = j;
break;
}
}
string tmp = s.substr(, pos - );
int ww = ;
string shuzi = s.substr(pos, s.size() - pos);
for (int j = ; j < shuzi.size(); j++)
{
ww = ww * + shuzi[j] - '';
}
mp[tmp] = i;
w[i] = ww;
//cout << tmp << " " << ww << endl;
}
for (int i = ; i <= m; i++)
{
getline(cin, s);
int pos1 = -;
for (int i = ; i < s.size(); i++)
{
if (s[i] == '-')
{
pos1 = i;
break;
}
}
string t1 = s.substr(, pos1 - );
string t2 = s.substr(pos1 + , s.size() - pos1 - );
int id1 = mp[t1];
int id2 = mp[t2];
in[id2] |= ( << id1);
}
dp[] = ;
for (int j = ; j < ( << n) - ; j++)
{
if (dp[j] < )
{
continue;
}
int num = ;
for (int i = ; i < n; i++)
{
num += (j >> i & );
}
for (int i = ; i < n; i++)
{
int now = j | ( << i);
if (j != now && (in[i] & j) == in[i])
{
dp[now] = max(dp[now], dp[j] + (num + )*w[i]);
}
}
}
cout << dp[( << n) - ] << endl;
}
return ;
} /*
1
3 2
Implementation 3
Dynamic Programming 10
Greedy 7
Greedy --> Dynamic Programming
Implementation --> Dynamic Programming
*/
H.模板题,待施工
gym100676 [小熊骑士限定]2015 ACM Arabella Collegiate Programming Contest的更多相关文章
- 边双连通缩点+树dp 2015 ACM Arabella Collegiate Programming Contest的Gym - 100676H
http://codeforces.com/gym/100676/attachments 题目大意: 有n个城市,有m条路,每条路都有边长,如果某几个城市的路能组成一个环,那么在环中的这些城市就有传送 ...
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)
A(By talker): 题意分析:以a(int) op b(int)形式给出两个整数和操作符, 求两个整数是否存在操作符所给定的关系 ,有则输出true,无则输出false: 思路:由于无时间复杂 ...
- 2015 ACM Arabella Collegiate Programming Contest
题目链接:https://vjudge.net/contest/154238#overview. ABCDE都是水题. F题,一开始分类讨论,结果似乎写挫了,WA了一发.果断换并查集上,A了. G题, ...
- 18春季训练01-3/11 2015 ACM Amman Collegiate Programming Contest
Solved A Gym 100712A Who Is The Winner Solved B Gym 100712B Rock-Paper-Scissors Solved C Gym 100712C ...
- ACM Arabella Collegiate Programming Contest 2015 F. Palindrome 并查集
题目链接:http://codeforces.com/gym/100676/attachments 题意: 给一个字符串,有一些约束条件,两个位置要相同,有一些是问号,求最后有多少种方案回文? 分析: ...
- ACM Arabella Collegiate Programming Contest 2015 H. Capital City 边连通分量
题目链接:http://codeforces.com/gym/100676/attachments 题意: 有 n 个点,m 条边,图中,边强连通分量之间可以直达,即距离为 0 ,找一个点当做首都,其 ...
- 2017 ACM Arabella Collegiate Programming Contest(solved 11/13)
省选考前单挑做点ACM练练细节还是很不错的嘛- 福利:http://codeforces.com/gym/101350 先来放上惨不忍睹的virtual participate成绩(中间跑去食堂吃饭于 ...
- 带权并查集:CF-2015 ACM Arabella Collegiate Programming Contest(F题)
F. Palindrome Problem Description A string is palindrome if it can be read the same way in either di ...
- 2015 ACM Syrian Collegiate Programming Contest
A. My Friend of Misery 计算出答案的上下界即可. 时间复杂度$O(n)$. #include<bits/stdc++.h> using namespace std; ...
随机推荐
- Python time.md
time模块 Comparing Clocks time.clock():在Unix 上,返回当前的处理器时间,以浮点数秒数表示. time.monotonic():返回一个单调时钟的值(在分秒内), ...
- Geeks : Kruskal’s Minimum Spanning Tree Algorithm 最小生成树
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/.未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- P1439 【模板】最长公共子序列
题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输出格式 输入格式: 第一行是一个数n, 接下来两行,每行为n个数,为自然数1-n的一个排列. 输出格式: 一个数,即最长公共子 ...
- programming-languages学习笔记--第9部分
programming-languages学习笔记–第9部分 */--> pre.src {background-color: #292b2e; color: #b2b2b2;} pre.src ...
- 【node.js】Stream(流)
Stream 有四种流类型: Readable - 可读操作. Writable - 可写操作. Duplex - 可读可写操作. Transform - 操作被写入数据,然后读出结果. 所有的 St ...
- 禁止 "启动时恢复任何注册的应用程序"
在关闭计算机时 有些程序会进行注册 并在下次启动时恢复关闭前的状态(Restart Manager) 比如Chrome浏览器 应用程序实现这一功能可以调用RegisterApplicationRest ...
- 创建ROS工程結構
图像化显示目录工程结构:tree $ sudo apt install tree 1.创建ROS工作空间 $ mkdir -p catkin_ws/src # Create mutil-level d ...
- python redis 的基本操作指令
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' redis基本命令和基本用法详解 1.redis连接 2.redis连接池 3.redis基本命令 ...
- 视频直播时的QoS策略
一.如何判断当前的网络状况 可以以发送一帧视频数据的时间为依据,判断当前网络拥塞情况. 网络中出现丢包和抖动,导致接收端接收数据超时,会激发发送端数据重传,重传机制本身挤占网络带宽,导致send ...
- 安装MySQL56时,停止在start service这一步
问题: 在安装MySQL56时,安装程序执行到start service这一步就不能完成,系统一直提示“安装时间比预期的的长,是否停止安装这一步(configuration of mysql seve ...