1001: 可以证明(扩展欧几里得),只要卡片中有两个卡片互素,旁边点就是可达的。 因此只需要算出所有卡片不互素的情况有多少种,可用容斥原理。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector> using namespace std; typedef __int64 ll; ll A, B;
ll prime[] = {, , , , , , , , };
ll ans;
bool vis[]; vector<ll> yinzi(ll x) {
vector<ll> res;
for (int i = ; i < ; i++) if ( == x%prime[i]) {
res.push_back(prime[i]);
}
return res;
} ll my_pow(ll d, ll n) {
ll res = ;
while (n) {
if (n&) res *= d;
d *= d;
n >>= ;
}
return res;
} void dfs(const vector<ll> &d, int cnt, ll tmp, ll flag) {
if (cnt >= d.size()) return ;
int i = cnt;
ll t = B/d[i]/tmp;
ans += flag * my_pow(t, A);
dfs(d, cnt+, tmp*d[i], -*flag);
dfs(d, cnt+, tmp, flag);
} int main() {
// freopen("1001.txt", "r", stdin); int T;
scanf("%d", &T); while (T--) {
scanf("%I64d%I64d", &A, &B);
ans = my_pow(B, A);
dfs(yinzi(B), , , -);
memset(vis, false, sizeof(vis));
printf("%I64d\n", ans);
} return ;
}

1001

1002: 括号匹配,区间dp

 #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAXN = ; int dp[MAXN][MAXN];
char str[MAXN]; int dfs(int L, int R) {
if (-!=dp[L][R])
return dp[L][R];
int &res = dp[L][R] = ;
if (('('==str[L]&&str[R-]==')') || ('['==str[L]&&str[R-]==']'))
res = dfs(L+, R-) + ;
for (int i = L+; i < R; i++)
res = max(res, dfs(L, i)+dfs(i, R));
return res;
} int main() {
#ifdef Phantom01
freopen("1002.txt", "r", stdin);
#endif // Phantom01 int Case;
scanf("%d", &Case);
gets(str); while (Case--) {
gets(str);
int len = strlen(str);
memset(dp, -, sizeof(dp));
printf("%d\n", len - *dfs(, len));
} return ;
}

1002

1003:最小生成树

已知经纬度求球面距离 连接

代码略。

1004: 直接大数模拟。

代码略

2014 CodingTrip - 携程编程大赛 (预赛第一场)的更多相关文章

  1. 2014 CodingTrip - 携程编程大赛 (预赛第二场)

    1001: 食物链(poj1182),直接贴代码,稍作可过 并查集 // // main.cpp // 携程1 // // Created by zhang on 14-4-11. // Copyri ...

  2. 【解题报告】[动态规划] CodingTrip - 携程编程大赛 (预赛第一场)- 聪明的猴子

    原题: 聪明的猴子 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Problem D ...

  3. 位图像素的颜色 携程编程大赛hdu

    位图像素的颜色 Time Limit: 2000/1000 MS (Java/Others)    MemoryLimit: 32768/32768 K (Java/Others) Total Sub ...

  4. 全国高校绿色计算大赛 预赛第一阶段(C++)第4关:计算日期

    挑战任务 我们吃的食物都有保质期,现在食品监督管理局想要制作一个能准确计算食品过期日期的小程序,需要请你来进行设计. 例如:A食品在2018年1月1日生产,保质期是20天,则它的过期日期在2018年1 ...

  5. 全国高校绿色计算大赛 预赛第一阶段(C++)第3关:旋转数组

    挑战任务 在计算机中,一张数字图像,可以被看做是一个矩阵或者说数组. 学过线性代数的同学对矩阵肯定不陌生.一般来说,图像是一个标准的矩形,有着宽度(width)和高度(height).而矩阵有着行(r ...

  6. 全国高校绿色计算大赛 预赛第一阶段(C++)第2关:扔桃子

    挑战任务 动物园有一只小猴子喜欢吃桃子,不过它有个很独特的习惯,每次都把找到的桃子分成相等的两份,吃掉一份,留一份.如果不能等分,小猴子就会丢掉一个然后再分.第二天再继续这个过程,直到最后剩一个桃子了 ...

  7. 全国高校绿色计算大赛 预赛第一阶段(C++)第1关:将字符串反转

    挑战任务 将输入的字符串str进行反转. 编程要求 补全右侧vector<char> inversion(string str)函数实现字符串的反转并返回反转之后的字符串,其中函数参数st ...

  8. HDU 4508 沼泽湿地系列故事——记住减肥I (2013腾讯编程马拉松预赛第一)

    pid=4508">http://acm.hdu.edu.cn/showproblem.php?pid=4508 题目大意: 给定一些数据. 每组数据以一个整数n開始,表示每天的食物清 ...

  9. 全国高校绿色计算大赛 预赛第一阶段(Python)

    第1关将字符串反转 #!/usr/bin/env python # -*- coding: utf-8 -*- class Task: def inversion(self, str): # **** ...

随机推荐

  1. 关于js里的document.compatmode

    document.compatmode为获取页面的渲染模式. 其中有两个渲染模式 1.CSS1Compat(标准模式).浏览器宽度:document.documentElement.clientHei ...

  2. Python学习---Day96

    转载:http://www.cnblogs.com/wupeiqi/articles/6229292.html Scrapy Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可 ...

  3. git 常用操作命令行

    mkdir files : 创建一个名字为files的文件夹 cd files : 切换目录到files pwd ; 显示当前所在目录 ls -ah : 查看本地隐藏不可见的文件夹 git init ...

  4. execlp(3) - Linux手册

    名称: execl, execlp, execle, execv, execvp, execvpe:执行文件 总览: #include <unistd.h> extern char **e ...

  5. C语言实现简化的正则表达式

    语法: 正则表达式和待匹配字符串都是一行 "^" 标记正则表达式的开始 "$" 标记正则表达式的结束 "*" 匹配前面的子表达式零次或多次 ...

  6. Python学习————列表的增删改查

    增加:li.append(对象):追加 注:print(li.append())--->是Noneli.insert(索引,对象):插入到相应位置li.extend(对象):可迭代的添加到尾部, ...

  7. WPF 获取应用的所有窗口

    原文:WPF 获取应用的所有窗口 本文告诉大家如何获取应用内的所有窗口,无论这些窗口有没显示 在 WPF 可以通过 Application.Current.Windows 列举应用的所有窗口 fore ...

  8. LibSVM C/C++

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50179779 在LibSVM的库的sv ...

  9. Inter-partition communication in multi-core processor

    A multi-core processor includes logical partitions that have respective processor cores, memory area ...

  10. sqoop从mysql导入到hdfs出现乱码问题

    最近把hive元数据库的快照数据导入到hdfs中,以便对历史的元数据进行查询. 命令如下: sqoop import -D mapred.job.queue.name=do.production -- ...