HDU 5832 - A water problem

题意:有两颗星球,一年的长度分别为37天和173天。问第n天时它们是否为新年的第一天。

思路:显然  n 同时被37和173整除时,两种历法都在新年第一天,即 n 是 37*173=10001的倍数。

坑点:n的长度会达到1e7,我以为要用读入挂之类的,手写用getchar()读入却TLE,直接scanf("%s", n)就没事。

#include<iostream>
#include<cstdio>
using namespace std; int main() {
int cas = ;
char n;
int val = ;
while((n=getchar())!=EOF) {
if(n!='\n') {
val = val * + (n-'');
val %= ;
} else {
printf("Case #%d: %s\n", ++cas, val==?"YES":"NO");
val = ;
}
}
return ;
}

AC代码:

#include<iostream>
#include<cstdio>
using namespace std;
char n[];
int main() {
int cas = ;
while(scanf("%s", n)!=EOF) {
int val = ;
for(int i=;n[i];i++) {
val = val * + (n[i]-'');
val %= ;
}
printf("Case #%d: %s\n", ++cas, val==?"YES":"NO");
}
return ;
}

HDU 5833 - Zhu and 772002

题意:给n个正整数(最大素因子不超过2000),求n个数组成平方数的方案数。

思路:高斯消元模板题。

把每个数的素因子加入矩阵A中,设A高斯消元后的秩为 r,则自由元个数为 n - r, 组合方案数为 2^(n - r) - 1。

手写的快速幂函数pow跟C++库重名了导致一直WA。。。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ;
const int maxp = ;
const int mod = 1e9+;
typedef long long ll; int pri[maxp], cnt;
int A[maxp][maxn]; void init() {
for(int i=;i<=maxp;i++) {
bool f = true;
for(int j=;j*j<=i;j++) {
if(i%j==) {
f = false;
break;
}
}
if(f) pri[cnt++] = i;
}
} int add(int k, ll val) {
int row = -;
for(int i=;i<cnt && val>=pri[i];i++) {
while(val%pri[i]==) {
A[i][k] ^= ; val /= pri[i];
row = i;
}
}
return row;
} ll mypow(ll a, ll n) {
ll res = ;
while(n) {
if(n&) res = res * a % mod;
a = a * a % mod;
n >>= ;
}
return res;
} int gauss(int m, int n) {
int i = , j = ;
int r;
while(i<m && j<n) {
r = i;
for(int k=i;k<m;k++) {
if(A[k][j]) {
r = k;
break;
}
} if(A[r][j]) {
if(r!= i) {
for(int k=;k<=n;k++)
swap(A[r][k], A[i][k]);
}
for(int u=i+;u<m;u++) {
if (A[u][j]) {
for (int k=i;k<=n;k++)
A[u][k] ^= A[i][k];
}
}
i++;
}
j++;
}
return i;
} int main() { init();
int cas = , T; cin>>T; while(cas<T) {
memset(A, , sizeof(A)); int n, row = ;
ll ai;
scanf("%d", &n);
for(int i=;i<n;i++) {
scanf("%lld", &ai);
row = max(row, add(i, ai));
}
printf("Case #%d:\n", ++cas);
int r = gauss(row+, n);
printf("%lld\n", mypow(, n-r)-);
} return ;
}

HDU 5835 - Danganronpa

题意:给n个礼物,每个礼物a[i]件,分配给学生,每人两件。要求1件可以任意,另一件必须相邻学生种类不同。求可以分出去的最大学生数量。

思路:分析一下可以发现,礼物能否发完只取决于最多数量的那种。先排序,如果最多的礼物减去总和的一半比剩下种类的礼物总数还要多,则能发出去的数量由剩下种类的礼物决定,即 (sum-a[n-1])*2+1。否则全部都能发出去,人数即为 sum/2。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[];
int main()
{
int cas=, t; cin>>t;
while(cas<t) {
int n; scanf("%d", &n);
int sum = ;
for(int i=;i<n;i++) {
scanf("%d", &a[i]);
sum += a[i];
}
sort(a, a+n); printf("Case #%d: %d\n", ++cas, min(sum/, (sum-a[n-])*+));
}
return ;
}

HDU 5839 - Special Tetrahedron

题意:给定空间中 n个点(n<=100),求满足两个条件的特殊四面体的个数。条件1:至少4条边长度相同;条件2:如果只有4条边长度相同,则剩下两条边不能相邻。

思路:C(100, 4)不大,时限4s,暴力枚举即可。四个点不能共面,先求点积再叉积判断是否为0,即四面体体积不能为0。

TM我再次敲错了向量叉积函数cross。。。逐行debug才发现

AC代码:

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct P {
int x, y, z;
P(int xx=, int yy=, int zz=):x(xx), y(yy), z(zz) {}
P operator-(const P& a) {
return P(x-a.x, y-a.y, z-a.z);
}
P operator*(const P& b) {
return P(y*b.z-z*b.y, z*b.x-x*b.z, x*b.y-y*b.x);
}
int dis() {
return x*x + y*y + z*z;
}
void print() {
printf("(%d %d %d)\n", x, y, z);
}
}p[];
int cross(const P& a, const P& b) {
return a.x*b.x + a.y*b.y + a.z*b.z;
} int main()
{
int cas=, t; cin>>t;
while(cas<t) {
int n;
scanf("%d", &n);
for(int i=;i<n;i++) {
scanf("%d %d %d", &p[i].x, &p[i].y, &p[i].z);
} int ans = ;
for(int i=;i<n;i++) {
for(int j=i+;j<n;j++) {
for(int k=j+;k<n;k++) {
int dis1 = (p[i]-p[j]).dis();
int dis2 = (p[i]-p[k]).dis();
int dis3 = (p[j]-p[k]).dis();
if(dis1!=dis2 && dis2!=dis3 && dis1!=dis3) continue; int equa = -; P t1, t2;
if(dis1==dis2 && dis1!=dis3) equa = dis1, t1 = p[j], t2 = p[k];
if(dis1==dis3 && dis1!=dis2) equa = dis1, t1 = p[i], t2 = p[k];
if(dis2==dis3 && dis1!=dis2) equa = dis2, t1 = p[i], t2 = p[j]; // if(equa==-1) equa = dis1;
for(int l=k+;l<n;l++) {
if(cross((p[i]-p[j])*(p[i]-p[k]), p[i]-p[l])==) continue; if(equa!=-) {
if((p[l]-t1).dis()==equa && (p[l]-t2).dis()==equa) {
++ans;
// printf("%d %d %d %d\n", i, j, k, l);
}
} else { // 底面三边相等
int dis4 = (p[l]-p[i]).dis();
int dis5 = (p[l]-p[j]).dis();
int dis6 = (p[l]-p[k]).dis();
if(dis4==dis1 && dis5==dis1 || dis4==dis1 && dis6==dis1 || dis5==dis1 && dis6==dis1) {
++ans;
// printf("%d %d %d %d\n", i, j, k, l);
}
} }
}
}
} printf("Case #%d: %d\n", ++cas, ans);
}
return ;
}

HDU 5842 - Lweb and String

题意:给一个字符串,可以把每个字母映射到数字。问变换后的最长上升子序列的长度是多少。

题解:显然答案为不同字母的个数。

代码:略。

2016 CCPC网络选拔赛 部分题解的更多相关文章

  1. 2016 ccpc 网络选拔赛 F. Robots

    Robots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  2. HDU 5898 odd-even number(2016沈阳网络选拔赛 数位DP)

    定义DP[pos][pre][odd][even],pos代表当前数位,pre代表前一位的数值,odd代表到前一位连续的奇数个数,even代表到前一位连续偶数个数. odd和even肯定至少有一个为0 ...

  3. hdoj6708 2019 CCPC网络选拔赛 1007 Windows Of CCPC

    #include <cstdio> #include <iostream> #include <algorithm> using namespace std; ch ...

  4. hdoj6703 2019 CCPC网络选拔赛 1002 array

    题意 description You are given an array a1,a2,...,an(∀i∈[1,n],1≤ai≤n). Initially, each element of the ...

  5. 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree

    Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...

  6. [BFS,A*,k短路径] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 path (Problem - 6705)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6705 path Time Limit: 2000/2000 MS (Java/Others)    Mem ...

  7. [贪心,dp] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 Fishing Master (Problem - 6709)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Fishing Master Time Limit: 2000/1000 MS (Java/Othe ...

  8. 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛(8/11)

    $$2019中国大学生程序设计竞赛(CCPC)\ -\ 网络选拔赛$$ \(A.\hat{} \& \hat{}\) 签到,只把AB都有的位给异或掉 //#pragma comment(lin ...

  9. HDU 6447 - YJJ's Salesman - [树状数组优化DP][2018CCPC网络选拔赛第10题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 Problem DescriptionYJJ is a salesman who has tra ...

随机推荐

  1. 【POJ】2253 Frogger

    = =.请用C++提交.. 如果有朋友能告诉我G++和C++交题什么机制..我感激不尽.G++杀我. 题目链接:http://poj.org/problem?id=2253 题意:青蛙A要去找B约会, ...

  2. mysql查询小技巧

    如果所传bookTypeName为空则执行select * from t_bookType(搜索框里未输入信息) 否则追加 and bookTypeName like  '%"+bookTy ...

  3. OpenCV-Python Tutorials目录

    版本 3.4.6 1 Introduction to OpenCV OpenCV介绍Learn how to setup OpenCV-Python on your computer! 2 Gui F ...

  4. 百度开平台BAE搭建网站

    百度开平台BAE搭建网站 一.注册:在百度云注册账号,并且登陆 然后实名验证 二.开始搭建 三.部署项目:我们来把我们的项目提交上去 填写百度云的账号密码 四.删除:删除部署项目 以上就是百度开平台B ...

  5. vue SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

    在使用vue_cli时出现如下错误: 原因是  node  版本太低 应该升级

  6. 家庭-养老院模型理解IOC和DI

    控制反转 IOC 1. 概念 应用内部不负责依赖对象的创建和维护, 由第三方负责, 这样控制权就由应用内部转移到外部容器, 控制权的转移就是所谓的反转. 2. 比喻 有一户家庭(应用)有个老人(依赖对 ...

  7. 文件的操作repeat

    #_author:来童星#date:2019/12/15import os#1# print(os.name)# nt------>windows操作系统#2 用于获取当前操作系统的换行符# p ...

  8. Linux课程---15、域名相关

    Linux课程---15.域名相关 一.总结 一句话总结: 先购买域名,再备案,再解析,域名即可使用 1.域名备案是怎么回事(比如二级域名,三级域名)? 每个二级域名需要备案一次,三级域名不需要备案, ...

  9. Kafka和RabbitMQ 对比

    1)  Kafka成为业界大数据松耦合架构,异步,队列 特点:吞吐量高50m/s. Kafka和RabbitMQ都是MQ机制,它差异 Kafka作为大数据产品,可以作为数据源,也可以作为结果数据中转 ...

  10. Keras+Yolo 目标检测

    参考:https://www.cnblogs.com/tensorflownews/p/8922359.html Github:https://github.com/qqwweee/keras-yol ...