暑期测试2 题目积累中
类型1 求素数
例1,1
素数个数统计
,统计100到300之间素数共有多少个,计算所有素数的和并输出结果
时间复杂度o(n2)
#include <stdio.h>
void main()
{
int i,j,n=0,sum=0;
for(i=100;i<=300;i++)
{
for(j=2;j<i;j++)
UVA 10891 Game of Sum——dp
定义dp[i][j]表示面对区间[i,j]的数执先手一方可获得的最大数字和
注意题目描述貌似不太严谨,差距可以是负的,一开始加绝对值错了。。。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
ty...
HDU 6415 Rikka with Nash Equilibrium——dp
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 81;
int T, n, m, mod;
ll dp[2][maxn][...
UVA 11825 Hackers' Crackdown——dp
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int kase, n, a[20], un[1<<16], dp[1<<16];
int main() {
while...
UVA 10859 Placing Lampposts——dp
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1010;
int T, n, m;
bool vi...
HDU 6434 Problem I. Count
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e7;
const int maxn = N+10;
int T,n;
int primes,prime[maxn],phi[maxn];
bool vis[maxn];
LL ans[maxn];
void init...
UVALive 3983 Robotruck——单调队列优化dp
注意一下一开始要把原点入队
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 1e5 + 10;
int T, C, n...
HDU 5887 Herbs Gathering——剪枝
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
ll N, V, MAX;
struct Data {...
UVALive 4794 Sharing Chocolate——dp
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
bool judge[(1<<15)+10];
int kase, N, X, Y, a[20], sum[(1<<15)+10...
HDU 5884 Sort——二分+O(n)哈弗曼树
两个队列搞一搞就搞出O(n)的哈弗曼树了
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
char ...
HDU 5883 HDU - 5883——欧拉路
注意判一下欧拉回路的情况,这种情况下需要找一个点再异或一次
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 1...
HDU 5886 Tower Defence——dp
预处理出最长链,若断边不在最长链上,那么答案依旧是最长链,否则计算断开后的最长链,这个做一次树形dp就可以了
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll...
UVALive 4256 Salesmen——dp
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
int T, n, m, L, a[210];
...
UVA 11552 Fewest Flops——dp
注意当前块结尾字符若等于前一个块的结尾字符,要判一下当前块的字符总数是否为1
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1010;
const int INF...
今日推荐
周排行