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的更多相关文章

  1. 边双连通缩点+树dp 2015 ACM Arabella Collegiate Programming Contest的Gym - 100676H

    http://codeforces.com/gym/100676/attachments 题目大意: 有n个城市,有m条路,每条路都有边长,如果某几个城市的路能组成一个环,那么在环中的这些城市就有传送 ...

  2. Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)

    A(By talker): 题意分析:以a(int) op b(int)形式给出两个整数和操作符, 求两个整数是否存在操作符所给定的关系 ,有则输出true,无则输出false: 思路:由于无时间复杂 ...

  3. 2015 ACM Arabella Collegiate Programming Contest

    题目链接:https://vjudge.net/contest/154238#overview. ABCDE都是水题. F题,一开始分类讨论,结果似乎写挫了,WA了一发.果断换并查集上,A了. G题, ...

  4. 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 ...

  5. ACM Arabella Collegiate Programming Contest 2015 F. Palindrome 并查集

    题目链接:http://codeforces.com/gym/100676/attachments 题意: 给一个字符串,有一些约束条件,两个位置要相同,有一些是问号,求最后有多少种方案回文? 分析: ...

  6. ACM Arabella Collegiate Programming Contest 2015 H. Capital City 边连通分量

    题目链接:http://codeforces.com/gym/100676/attachments 题意: 有 n 个点,m 条边,图中,边强连通分量之间可以直达,即距离为 0 ,找一个点当做首都,其 ...

  7. 2017 ACM Arabella Collegiate Programming Contest(solved 11/13)

    省选考前单挑做点ACM练练细节还是很不错的嘛- 福利:http://codeforces.com/gym/101350 先来放上惨不忍睹的virtual participate成绩(中间跑去食堂吃饭于 ...

  8. 带权并查集: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 ...

  9. 2015 ACM Syrian Collegiate Programming Contest

    A. My Friend of Misery 计算出答案的上下界即可. 时间复杂度$O(n)$. #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. ECharts 定制 label 样式

    起因 实现对 label 的样式定制,自定义字体颜色.大小等属性:效果如下图 实现   itemStyle: {   normal: {   color: '#f7ba0e',   label: { ...

  2. 使用python来搞定redis的订阅功能

    好久没写博客了.   最近公司开了新项目,我负责的内容之一是系统的后端.具体项目内容我就不介绍了,但是用到的技术有些还是很有趣的,值得记录一下.今天介绍的就是其中一个:利用redis的pubsub订阅 ...

  3. python第十四课--排序及自定义函数之自定义函数(案例四)

    整理:4中最常见的自定义函数模型1).无参无返回值2).无参有返回值3).有参无返回值4).有参有返回值 #定义无参无返回值自定义函数 def func1(): print('hello method ...

  4. 在CentOS7上部署 Kubernetes集群

    yum -y install  etcd docker  flannel kubenetes 一般会遇到没有k8s源的问题,先 yum update -y 看是否有效,如果还是没用就创建yum 源,再 ...

  5. c++ 浅拷贝和深拷贝 指针和引用的区别 malloc(free)和new(delete)的区别 重载重写重定义

    4.malloc(free)和new(delete)的区别 malloc()函数: 1.1 malloc的全称是memory allocation,中文叫动态内存分配. 原型:extern void ...

  6. 细数用anaconda安装mayavi时出现的各种问题

    这段时间需要利用mayavi做科学数据的处理,因此需要利用到mayavi库,但是官网上面的指示说:如果安装了anaconda,其中自带各种科学库,但是实践中,并没有发现mayavi. 官方网站导航:m ...

  7. [Luogu P1120]小木棍·加强版

    #\(\mathcal{Description}\) 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过 \(50\) . 现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开 ...

  8. 一个考验c语言和数据结构功底的小项目

    想测一下自己c语言学习水平的朋友可以做一下这个项目试试,能做出来说明c语言已经入门了   #include<stdio.h> #include<stdlib.h> #inclu ...

  9. 50个国内外最棒的C/C++源码站点分享

    C/C++是最基本的编程语言.这里列出了50名优秀站点和网页清单,这些站点提供c/c++源码.这份清单提供了源码的链接以及它们的小说明.我已 尽力包含最佳的C/C++源码的站点.这不是一个完整的清单, ...

  10. java 工作流项目源码 SSM 框架 Activiti-master springmvc 集成web在线流程设计器

    即时通讯:支持好友,群组,发图片.文件,消息声音提醒,离线消息,保留聊天记录 (即时聊天功能支持手机端,详情下面有截图) 工作流模块---------------------------------- ...