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; ...
随机推荐
- log4j.properties的配置详解
log4j.rootLogger=ERROR,A1log4j.appender.A1=org.apache.log4j.ConsoleAppenderlog4j.appender.A1.layout= ...
- linux批量远程多服务器FTP并下载文件的脚本
#!/bin/bashtime=`date +%Y%m`day=`date -d '-1 days' +%Y%m%d`localDir="/DBBackup/GameDB"cd $ ...
- java多线程之Callable、Future和FutureTask
Java并发编程:Callable.Future和FutureTask 在前面的文章中我们讲述了创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable接口. 这2种方式都有一 ...
- CentOS部署Kubernetes1.13集群-1(使用kubeadm安装K8S)
参考:https://www.kubernetes.org.cn/4956.html 1.准备 说明:准备工作需要在集群所有的主机上执行 1.1系统配置 在安装之前,需要先做如下准备.三台CentOS ...
- VMware 虚拟机安装
虚拟机下载 VMware官网地址:https://www.vmware.com/ 进行官网后,点击左边的下载图标,然后 作系统选择合适的产品,在这里以Windows系统为例,点击转至下载,如下图所示. ...
- smtp outlook邮件发送非授权码模式
1.起因:send fail SMTP AUTH extension not supported by server. 使用端口25 和587均失效出现此问题 首先前往outlook修改设置pop和I ...
- 【题解】洛谷P4158 [SCOI2009] 粉刷匠(DP)
次元传送门:洛谷P4158 思路 f[i][j][k][0/1]表示在坐标为(i,j)的格子 已经涂了k次 (0是此格子涂错 1是此格子涂对)涂对的格子数 显然的是 每次换行都要增加一次次数 那么当j ...
- 基于Jq的手写插件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- Vivado中xilinx_BRAM IP核使用
Vivado2017.2 中BRAM版本为 Block Memory Generator Specific Features 8.3 BRAM IP核包括有5种类型: Single-port RA ...
- mypwd的实现——20155328
mypwd的实现 分析 pwd不带参数时,实现的是查看并打印当前所在位置的绝对路径功能. 如图: 所以实现mypwd时重点在于循环打印路径名,循环的终止条件是是到了根目录.判定是否到达根目录的标准为: ...