比赛链接

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. SpringBoot2.0+ 使用Log4j2日志输出

    据说Log4j2相比log4j效率有很大提升. pom.xml导入 <dependency> <groupId>org.springframework.boot</gro ...

  2. ZJOI 2006 物流运输 bzoj1003

    题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪. ...

  3. 暑假集训test-8-14~8-15

    我不想写博客辣. 拖了三天的一起写,结果就是写不下去了...果然应该改一道写一道么.. 题面题解代码也懒得往博客上放了,屯U盘里了... 因为太菜还有两道没有改. 题解外的一些参考: lyc大佬的进程 ...

  4. RPC 编程

    我们从一个简单的 RPC "Hello, world!"的例子开始. 参考资料:MSDN: Win32 and COM Development -> Networking - ...

  5. 盒子阴影 box-shadow

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. 靖烜小哥哥之mybatis总结

    MyBatis是一个半自动映射的框架.“半自动”是相对于Hibernate全表映射而言的,MyBatis需要手动匹配提供POJO.SQL和映射关系,而Hibernate只需提供POJO和映射关系即可. ...

  7. selenium基础(警告框的处理)

    selenium基础(警告框的处理) 在webdriver中处理JavaScript所产生的的警告框有三种类型 alert confirm prompt 划转到警告框的方法是:driver.switc ...

  8. input 不显示输入的历史记录

    第一次在 input 输入后,下次就会自动显示输入历史记录,去掉这种默认效果的解决方案 <input name="username" type="text" ...

  9. 2019-7-2-asp-dotnet-core-通过图片统计-csdn-用户访问

    title author date CreateTime categories asp dotnet core 通过图片统计 csdn 用户访问 lindexi 2019-7-2 19:21:2 +0 ...

  10. 淼一淼A+B problem

    鲁迅:这可是道难题呢! 鲁迅:我没说过这话,不过确实在理. 某改题毕,但见LOJ之上有数「A+B」之AC记录.余亦尝闻A+B之趣味无穷,遂兴起而码之. 少顷,AC之,吾心所畅. #include< ...