套题链接:http://codeforces.com/contest/622
难度类型:基本都是想法题
A
题解
类型:二分
二分答案或者直接求根。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
LL get(LL x) {
return (1+x) * x / 2;
}
int main()
{
LL n;
scanf("%I64d", &n);
LL ans, l = 0, r = 1e8;
while (l <= r) {
LL mid = (l+r) / 2;
LL temp = get(mid);
if (temp < n) {
ans = temp;
l = mid+1;
} else {
r = mid-1;
}
}
printf("%I64d\n", n-ans);
return 0;
}
B
题解
类型:模拟
除啊,模啊,就出来。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
int main()
{
int h, m, a;
scanf("%d:%d%d", &h, &m, &a);
m += a;
h += m / 60;
m %= 60;
h %= 24;
printf("%02d:%02d\n", h, m);
return 0;
}
C
题解
类型:预处理
处理下某点后第一个不同的位置,或者之前第一个不同的位置。
线性扫就行,然后就能常数做出答案。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
const int N = 2e5+5;
int nxt[N];
int a[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", a+i);
nxt[i] = a[i]==a[i-1] ? nxt[i-1] : i-1;
}
int l, r, x;
while (m--) {
scanf("%d%d%d", &l, &r, &x);
if (a[r] == x) r = nxt[r];
printf("%d\n", l <= r ? r : -1);
}
return 0;
}
D
题解
类型:构造
传送门:http://blog.csdn.net/xc19952007/article/details/50655412
E
题解
类型:图论,搜索
传送门:http://blog.csdn.net/xc19952007/article/details/50655453