比赛链接

A题

如果当前数是1,那么后面无论是几都会加1或者当后面数是1的时候加2,所以记录一下后面的数中1的个数(加2)即可。

如果当前数是2,那么只有当后面的数为1或者为2时才可以加1,所以再记录一下后面数中2的个数即可。

 #include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; int a[], t, n, num1[], num2[]; int main() {
ios::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> n;
for (int i = ; i <= n; i++) cin >> a[i];
memset(num1, , sizeof(num1));
memset(num2, , sizeof(num2));
for (int i = n; i >= ; i--) {
num1[i] = num1[i + ];
num2[i] = num2[i + ];
if (a[i] == ) num1[i]++;
else if (a[i] == ) num2[i]++;
}
long long res = ;
for (int i = ; i <= n; i++) {
if (a[i] == ) {
res += n - i + num1[i + ];
} else if (a[i] == ) {
res += num1[i + ] + num2[i + ];
} else {
res += num1[i + ];
}
}
cout << res << endl;
}
return ;
}

B题

这题需要敏锐的洞察力啊,起码对我来说是这样!

手动向后推两项就可以发现,当N为2时,S = (a1 + 1) * (a2 + 1) - 1;

当N为3时,S = (a1 + 1) * (a2 + 1) * (a3 + 1) - 1

可以发现,一个序列的S值和其顺序无关,只和数有关。

 #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; const int MOD = 1e9 + ;
const int MAX_N = ;
const int MAX_V = ;
typedef long long LL;
#define rep(i, n) for (int i = (1); i <= (n); i++) int main() {
ios::sync_with_stdio(false);
int N;
LL res = ;
cin >> N;
rep (i, N) {
int x;
cin >> x;
res = (res + x + res * x) % MOD;
}
cout << res << endl;
return ;
}

C题

很裸的求逆,快速幂。

 #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; int extgcd(int a, int b, int &x, int &y) {
int d = a;
if (b != ) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = ; y = ;
}
return d;
} int mod_inverse(int a, int m) {
int x, y;
extgcd(a, m, x, y);
return (m + x % m) % m;
} int mod_pow(int a, int b, int m) {
long long res = ;
while (b) {
if (b & ) res = res * a % m;
a = ((long long)a * a) % m;
b >>= ;
}
return res;
} int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int a, b, x;
cin >> a >> b >> x;
if (b < ) {
a = mod_inverse(a, x);
b = -b;
}
cout << mod_pow(a, b, x) << endl;
}
return ;
}

D题

容斥原理模板题

 #include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
const int MAX_N = ;
int N;
int num[MAX_N];
LL n, ans;
LL gcd(LL a, LL b){
LL r;
while( b ){
r = a%b;
a = b;
b = r;
}
return a;
} void dfs( int id, LL Lcm, bool flag ){
Lcm = Lcm*num[ id ] / gcd( Lcm,num[ id ] );
if( flag ) ans += n/Lcm;
else ans -= n/Lcm;
for( int i=id+;i<= N;i++ ){
dfs( i,Lcm,!flag );
}
return;
} int main() {
ios::sync_with_stdio(false);
cin >> N;
for (int i = ; i <= N; i++) cin >> num[i];
int D;
cin >> D;
for (int i = ; i <= D; i++) {
LL l, r;
cin >> l >> r;
LL ansr = , ansl = ;
ans = ;
n = r;
for (int i = ; i <= N; i++) dfs(i, num[i], true);
ansr = ans;
ans = ;
n = l - ;
for (int i = ; i <= N; i++) dfs(i, num[i], true);
ansl = ans;
cout << ansr - ansl << endl;
}
return ;
}

E题

从难度来看这题算是简单的规律题。。可是比赛中却没敢去写。

通过数列的前几项可以很自然的和fib数联系在一起。我们需要做的就是统计每个二进制位上的值。

通过本题学习了bitset的使用,很好用,支持两个bitset间进行位运算,很方便。

 #include <cmath>
#include <bitset>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; const int MOD = 1e9 + ;
const int MAX_N = ;
typedef long long LL;
#define rep(i, n) for (int i = (1); i <= (n); i++)
const int NUM = ;
LL fib[NUM], sum[NUM]; LL mod_pow(LL a, LL b) {
LL res = ;
while (b) {
if (b & ) res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= ;
}
return res;
} bitset<NUM> solve(LL x) {
bitset<NUM> res;
while (x) {
int pos = upper_bound(sum, sum + NUM, x) - sum - ;
x -= sum[pos];
res.set(pos);
}
return res;
} int main() {
fib[] = ; fib[] = ;
sum[] = ; sum[] = ;
for (int i = ; i < NUM; i++) {
fib[i] = fib[i - ] + fib[i - ];
sum[i] = sum[i - ] + fib[i];
} ios_base::sync_with_stdio(false);
int N;
cin >> N;
bitset<NUM> res;
rep (i, N) {
LL x;
cin >> x;
res ^= solve(x);
}
LL ans = ;
for (int i = ; i < res.size(); i++) if (res.test(i)) ans = (ans + mod_pow(, i)) % MOD;
cout << ans << endl;
return ;
}

F题

待续。。

G题

待续。。

H题

待续。。

Ad Infinitum 8 - Math Programming Contest的更多相关文章

  1. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)

    Floor Function Time Limit: 10 Seconds      Memory Limit: 65536 KB a, b, c and d are all positive int ...

  2. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  3. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...

  4. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  5. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...

  6. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...

  7. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502  The 12th Zhejiang Provincial ...

  8. zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...

  9. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Demacia of the Ancients

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5504  The 12th Zhejiang Provincial ...

随机推荐

  1. iOS开发之SceneKit框架--SCNView.h

    1.SCNView 在macOS中,SCNView是NSView的子类,在iOS和tvOS中,SCNView是UIView的子类.SCNView用于显示SceneKit的3D场景,而需要设置场景的相关 ...

  2. 框架前期准备篇之AutoFac常见用法总结 转载

    框架前期准备篇之AutoFac常见用法总结 一. 说在前面的话 凡是大约工作在两年以上的朋友们,或多或少都会接触到一些框架搭建方面的知识,只要一谈到框架搭建这个问题或者最佳用法这个问题,势必会引起一点 ...

  3. ssm项目中使用拦截器加上不生效解决方案

    在很多时候,需要拦截器来帮助我们完成一些特定的工作,比如获取请求的参数,本身在request这种获取数据就是一次磁盘的io, 如果在filter中获取了参数,那么在controller中就不能获取相关 ...

  4. Linux 通用数据结构说明

    device_driver include/linux/device.h struct device_driver { const char             * name; /* 驱动名称 * ...

  5. Educational Codeforces Round 69 D E

    Educational Codeforces Round 69 题解 题目编号 A B C D E F 完成情况 √ √ √ ★ ★ - D. Yet Another Subarray Problem ...

  6. vc 获取窗口标题GetWindowText

    今天在写一个模块,具体功能是想时刻监控用户当前活动窗口,需要获取窗口标题以及其它相关信息,记得API GetWindowText就是用来做这个的,结果试了半天,有的获取成功了有的获取失败了,而且有关汉 ...

  7. uoj279 题目交流通道

    题目:告诉你每两个点之间的最短路距离.构造每条边边权<=m的无向完全图.求有多少种不同边权的图满足最短路限制?n<=400. 标程: #include<cstdio> #inc ...

  8. input 数值验证

    1.手动校验数字为整数 Number.isInteger <el-input class="radioInput" v-model.number="ruleForm ...

  9. antidependence and data hazard

    See below example. ADDD  F6, F0, F8 SUBD   F8, F10, F14 Some article would say that “ There’s an ant ...

  10. [JZOJ3168] 【GDOI2013模拟3】踢足球

    题目 描述 题目大意 有两个队伍,每个队伍各nnn人. 接到球的某个人会再下一刻随机地传给自己人.敌人和射门,射门有概率会中. 每次射门之后球权在对方111号选手. 某个队伍到了RRR分,或者总时间到 ...