1A

水题   然而看不仔细爆int了

c++

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
double n, m, a;
cin >> n >> m >> a;
ll ans = ll(ceil(n / a)) * ll(ceil(m / a));
cout << ans << endl;
return ;
}

py3

 import math
t = input().split()
n, m, a = map(int, t)
print(int(math.ceil(n / a) * math.ceil(m / a)))

1B

有毒的模拟水题......

 #include <bits/stdc++.h>
using namespace std; int main(){
int n;
cin >> n;
while(n--){
string s;
cin >> s;
bool flag = false;
int i = ;
while(i < s.size() && 'A' <= s[i] && s[i] <= 'Z') ++i;
for(; i < s.size(); ++i){
if('A' <= s[i] && s[i] <= 'Z'){
flag = true;
break;
}
}
if(flag){
int c = ;
int index = s.find('C');
string ans = "";
for(int i = index + ; i < s.size(); ++i) c = * c + s[i] - '';
while(c){
int k = c % ;
if(k == ){
ans += 'Z';
--c;
}
else ans += ('A' + k - );
c /= ;
}
reverse(ans.begin(), ans.end());
cout << ans << s.substr(, index-) << endl;
}
else{
int index = ;
string ans = "R";
int r = ;
for(; index < s.size(); ++index){
if('' <= s[index] && s[index] <= '') break;
r = * r + (s[index] - 'A' + );
}
ans += s.substr(index, s.size());
ans += 'C';
cout << ans << r << endl;
}
}
return ;
}

1C

mdzz。。。

余弦定理求三角形内角,也是圆上的圆周角,乘以2得圆心角

求三圆心角最大公约数得正多边形每一份的圆心角ang,2*pi/ang得出边数n

海伦公式+正弦定理得三角形外接圆半径r = (a * b * c) / (4 * s)

s = n * r * r * sin(ang) / 2

 #include <bits/stdc++.h>
using namespace std;
const double eps = 1e-;
double fgcd(double a, double b){
if (fabs(a) < eps)
return b;
if (fabs(b) < eps)
return a;
return fgcd(b, fmod(a, b));
}
double diameter(double a, double b, double c) {
double p = (a + b + c) / ;
double s = sqrt(p * (p - a) * (p - b) * (p - c));
return a * b * c / ( *s);
}
int main() {
double x[], y[], line[];
for(int i = ; i < ; ++i) scanf("%lf %lf", &x[i], &y[i]);
for(int i = ; i < ; ++i)
line[i] = sqrt((x[i] - x[(i+)%]) * (x[i] - x[(i+)%]) + (y[i] - y[(i+)%]) * (y[i] - y[(i+)%]));
double r = diameter(line[], line[], line[]);
double angle[];
for(int i = ; i < ; ++i)
angle[i] = acos( - line[i] * line[i] / ( * r * r));
angle[] = * acos(-) - angle[] - angle[];
double ang = fgcd(angle[], fgcd(angle[], angle[]));
printf("%.6f\n", r * r * sin(ang) / * ( * acos(-) / ang));
return ;
}

2A

模拟水题   略麻烦(说到底是思路不清淅不严谨+弱)

 #include <bits/stdc++.h>
using namespace std; struct info{
string name;
int score;
}aaa[];
map<string, int> game;
int main(){
int n;
cin >> n;
string name, ans;
int score;
for(int i = ; i < n; ++i){
cin >> name >> score;
aaa[i].name = name;
aaa[i].score = score;
game[name] += score;
}
int maxScore = -;
for(int i = ; i < n; ++i) maxScore = max(maxScore, game[aaa[i].name]);
map<string, int> tmp;
for(int i = ; i < n; ++i){
if(game[aaa[i].name] < maxScore) continue;
tmp[aaa[i].name] += aaa[i].score;
if(tmp[aaa[i].name] >= maxScore){
ans = aaa[i].name;
break;
}
}
cout << ans << endl;
return ;
}

2B

然后就2B了.....

求2最少几个5最少几个然后min(num_two, num_five)就是答案   剩下输出路径

 #include <bits/stdc++.h>
using namespace std; int matrix[][][];
int dp[][][];
int step[][][]; void print(int nx, int ny, int k){
if(nx == && ny == ) return ;
if(step[nx][ny][k]){
print(nx-, ny, k);
printf("D");
}
else{
print(nx, ny-, k);
printf("R");
}
}
int main(){
int n;
scanf("%d", &n);
int zerox = , zeroy = ;
for(int i = ; i <= n; ++i){
for(int j = ; j <= n; ++j){
int k;
scanf("%d", &k);
if(k == ){
zerox = i;
zeroy = j;
continue;
}
int numtwo = , numfive = ;
while(!(k & )){
++numtwo;
k >>= ;
}
while(k % == ){
++numfive;
k /= ;
}
matrix[i][j][] = numtwo;
matrix[i][j][] = numfive;
}
}
memset(dp, 0x3f, sizeof(dp));
dp[][][] = matrix[][][];
dp[][][] = matrix[][][];
for(int i = ; i <= n; ++i){
for(int j = ; j <= n; ++j){
if(i == && j == ) continue;
for(int k = ; k < ; ++k){
dp[i][j][k] = matrix[i][j][k] + min(dp[i-][j][k], dp[i][j-][k]);
if(dp[i-][j][k] < dp[i][j-][k]) step[i][j][k] = ;
}
}
}
int ans = min(dp[n][n][], dp[n][n][]);
if(ans == ) puts("");
else if(zerox && zeroy){
puts("");
int nx = , ny = ;
while(nx < zerox) ++nx, printf("D");
while(ny < zeroy) ++ny, printf("R");
while(nx < n) ++nx, printf("D");
while(ny < n) ++ny, printf("R");
return ;
}
else printf("%d\n", ans);
int k = dp[n][n][] < dp[n][n][] ? : ;
print(n, n, k);
return ;
}

2C

模拟退火   先放着

 #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define _pow(a) ((a)*(a))
const double eps = 1e-; struct circle{ double x, y, r; }c[];
double angle[];
int cx[] = {, , , -}, cy[] = {, -, , }; double dis(double x1, double y1, double x2, double y2){
return sqrt(_pow(x1 - x2) + _pow(y1 - y2));
} double calc(double x, double y){
for(int i = ; i < ; ++i) angle[i] = dis(x, y, c[i].x, c[i].y) / c[i].r;
double value = ;
for(int i = ; i < ; ++i) value += _pow(angle[i] - angle[(i + ) % ]);
return value;
} int main(){
double x = , y = ;
for(int i = ; i < ; ++i){
scanf("%lf %lf %lf", &c[i].x, &c[i].y, &c[i].r);
x += c[i].x / 3.0;
y += c[i].y / 3.0;
}
double deviation = calc(x, y);
double step = ;
for(int i = ; i <= 1e5; ++i){
bool flag = false;
double xx, yy;
for(int j = ; j < ; ++j){
double nx = x + cx[j] * step, ny = y + cy[j] * step;
double nDeviation = calc(nx, ny);
if(nDeviation < deviation){
deviation = nDeviation;
flag = true;
xx = nx;
yy = ny;
}
}
if(flag){
x = xx;
y = yy;
}
else step /= 2.0;
}
if(deviation <= eps) printf("%.5f %.5f\n", x, y);
return ;
}

3A

水题  但是大神的代码总是让我amazing,简单清晰直接

 #include <bits/stdc++.h>
using namespace std; int main(){
char s[], t[];
scanf("%s %s", s, t);
int a = s[] - t[], b = s[] - t[];
char c = a > ? 'L' : (a = -a, 'R');
char d = b > ? 'D' : (b = -b, 'U');
printf("%d", a > b ? a : b);
while(a || b){
puts("");
if(a) --a, putchar(c);
if(b) --b, putchar(d);
}
return ;
}

3B

分开按capacity排序  再维护前缀和  再枚举space为1的船的数量

代码好丑...........

 #include <bits/stdc++.h>
using namespace std; struct vihecle{
int id;
int cpa;
}p1[], p2[];
int presum1[], presum2[]; bool cmp(vihecle a, vihecle b){
return a.cpa > b.cpa;
} int main(){
int n, v;
cin >> n >> v;
int i1 = , i2 = ;
presum1[] = presum2[] = ;
for(int i = ; i < n; ++i){
int t, pp;
cin >> t >> pp;
if(t == ){
p1[i1].cpa=pp;
p1[i1++].id=i+;
}
else{
p2[i2].cpa=pp;
p2[i2++].id=i+;
}
}
sort(p1, p1 + i1, cmp);
sort(p2, p2 + i2, cmp);
for(int i = ; i <= i1; ++i) presum1[i] = presum1[i-] + p1[i-].cpa;
for(int i = ; i <= i2; ++i) presum2[i] = presum2[i-] + p2[i-].cpa;
int ans = , ii1 = , ii2 = ;
for(int i = ; i <= i1; ++i){
if(i > v) break;
int tmp = presum1[i] + presum2[min((v-i)/, i2)];
if(tmp > ans){
ans = tmp;
ii1 = i;
ii2 = min((v - i) / , i2);
}
}
cout << ans << endl;
for(int i = ; i < ii1; ++i) cout << p1[i].id << " ";
for(int i = ; i < ii2; ++i) cout << p2[i].id << " ";
return ;
}

3C

恶心的模拟..........讲真......玩起来容易写起来恶心.......

 #include <bits/stdc++.h>
using namespace std; char g[][];
int c1, c2;
bool f1, f2; int main(){
for(int i = ; i < ; ++i) scanf("%s", g[i]);
c1 = c2 = ;
f1 = f2 = false; for(int i = ; i < ; ++i)
if(g[i][] == g[i][] && g[i][] == g[i][])
if(g[i][] == 'X') f1 = true;
else if(g[i][] == '') f2 = true;
for(int i = ; i < ; ++i)
if(g[][i] == g[][i] && g[][i] == g[][i])
if(g[][i] == 'X') f1 = true;
else if(g[][i] == '') f2 = true;
if(g[][] == g[][] && g[][] == g[][])
if(g[][] == 'X') f1 = true;
else if(g[][] == '') f2 = true;
if(g[][] == g[][] && g[][] == g[][])
if(g[][] == 'X') f1 = true;
else if(g[][] == '') f2 = true; for(int i = ; i < ; ++i)
for(int j = ; j < ; ++j)
if(g[i][j] == 'X') ++c1;
else if(g[i][j] == '') ++c2;
if(c1 == c2 || c1 == c2 + ){
if(f1 && f2) puts("illegal");
else if(f1 && !f2){
if(c1 == c2 + ) puts("the first player won");
else puts("illegal");
}
else if(!f1 && f2){
if(c1 == c2) puts("the second player won");
else puts("illegal");
}
else{
if(c1 + c2 == ) puts("draw");
else if(c1 + c2 < ){
if(c1 == c2) puts("first");
else if(c1 == c2 + ) puts("second");
}
else puts("illegal");
}
}
else puts("illegal");
return ;
}

3D

对于处理中每一个过程都有'('不少于')',将'?'置为')',若'('少于')'则在前面的'?'中拿出转换价值最小的进行转换

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll; int main(){
string s;
cin >> s;
ll cnt = , ans = ;
priority_queue<pair<int, int> > q;
for(int i = ; i < s.size(); ++i){
if(s[i] == '(') ++cnt;
else if(s[i] == ')') --cnt;
else{
int a, b;
cin >> a >> b;
ans += b;
--cnt;
s[i] = ')';
q.push(make_pair(b - a, i));
}
if(cnt < ){
if(q.empty()) break;
pair<int, int> p = q.top();
q.pop();
ans -= p.first;
s[p.second] = '(';
cnt += ;
}
}
if(cnt) cout << "-1" << endl;
else cout << ans << endl << s << endl;
return ;
}

4A

超级水......

 #include <bits/stdc++.h>
using namespace std; int main(){
int n;
cin >> n;
cout << (((n & ) || n == ) ? "NO" : "YES") << endl;
return ;
}

4B

水,随便贪一下

 #include <bits/stdc++.h>
using namespace std; struct {
int mini, maxi;
}p[]; int main(){
int d, maxSum;
cin >> d >> maxSum;
int totalMin = , totalMax = ;
for(int i = ; i < d; ++i) cin >> p[i].mini >> p[i].maxi, totalMin += p[i].mini, totalMax += p[i].maxi;
if(totalMin > maxSum || totalMax < maxSum)
cout << "NO" << endl;
else{
cout << "YES" << endl;
int t = maxSum - totalMin;
for(int i = ; i < d; ++i){
int ansi = p[i].mini;
if(t){
ansi = min(p[i].maxi, ansi + t);
t -= (ansi - p[i].mini);
}
cout << ansi << " \n"[i == d-];
}
}
return ;
}

4C

水,输入保证只有小写字母,map水过

 #include <bits/stdc++.h>
using namespace std; int main(){
int n;
cin >> n;
map<string, int> name;
while(n--){
string s;
cin >> s;
if(name[s] == ) cout << "OK" << endl;
else cout << s << name[s] << endl;
++name[s];
}
return ;
}

4D

n^2的暴力dp.......

 #include <bits/stdc++.h>
using namespace std; int n;
struct env{
int w, h;
}p[];
int dp[], pre[]; int dfs(int k){
if(dp[k]) return dp[k];
for(int i = ; i <= n; ++i){
if(p[k].w < p[i].w && p[k].h < p[i].h){
if(dfs(i) + > dp[k]){
pre[k] = i;
dp[k] = dfs(i) + ;
}
}
}
return dp[k];
} int main(){
cin >> n;
for(int i = ; i <= n; ++i)
cin >> p[i].w >> p[i].h;
cout << dfs() << endl;
for(int i = pre[]; i > ; i = pre[i]) cout << i << " ";
cout << endl;
return ;
}

5A

 #include <bits/stdc++.h>
using namespace std; int main(){
string s;
int ans = , member = ;
while(getline(cin, s)){
if(s[] == '+') ++member;
else if(s[] == '-') --member;
else{
int len = s.end() - find(s.begin(), s.end(), ':') - ;
ans += member * len;
}
}
cout << ans << endl;
return ;
}

5B

一眼样例明白大概但是奇数的情况要交替........

 #include <bits/stdc++.h>
using namespace std; int main(){
vector<string> v;
string s;
int len = ;
while(getline(cin, s)){
v.push_back(s);
len = max(len, int(s.size()));
}
cout << string(len+, '*') << endl;
int k = -;
for(vector<string>::iterator i = v.begin(); i != v.end(); ++i){
int l = len - (*i).size();
string fr = string(floor(double(l)/), ' '), ba = string(ceil(double(l)/), ' ');
if(l & ){
if(!k) cout << "*" << ba << *i << fr << "*" << endl;
else cout << "*" << fr << *i << ba << "*" << endl;
k = ~k;
}
else cout << "*" << fr << *i << ba << "*" << endl;
}
cout << string(len+, '*') << endl;
return ;
}

5C

dp,让我智障好久的题........

 #include <bits/stdc++.h>
using namespace std; const int maxn = 1e6 + ;
int dp[maxn]; int main(){
ios::sync_with_stdio(false);
memset(dp, , sizeof(dp));
string s;
cin >> s;
stack<int> pos;
while(!pos.empty()) pos.pop();
int len = , sum = ;
for(int i = ; i < s.size(); ++i){
if(s[i] == '(') pos.push(i);
else if(!pos.empty()){
int j = pos.top();
pos.pop();
int tmpSize = i - j + ;
dp[i] = tmpSize + (j ? dp[j-] : );
if(dp[i] > len){
len = dp[i];
sum = ;
}
else if(dp[i] == len) ++sum;
}
}
cout << len << " " << sum << endl;
return ;
}

5D

运动学卧槽......放弃

分类还是渣的不成样子.....

 #include <bits/stdc++.h>
using namespace std; const double eps = 1e-;
double a, v, l, d, w, t1, t2, vd, vt, r; int fcmp(double x){
if(fabs(x) < eps) return ;
else return x < ? - : ;
} int main(){
scanf("%lf %lf %lf %lf %lf", &a, &v, &l, &d, &w);
vt = sqrt(w * w / + a * d);
r = l - d;
if(fcmp(d - v * v / / a) <= && fcmp(sqrt( * a * d) - w) <= ){
t1 = sqrt( * d / a);
vd = sqrt( * a * d);
}
else if(fcmp(d - v * v / / a) >= && fcmp(w - v) >= ){
t1 = d / v + v / / a;
vd = v;
}
else if(fcmp(v - vt) >= && fcmp(vt - w) >= ){
t1 = ( * vt - w) / a;
vd = w;
}
else{
t1 = d / v + ( * v - w) / a - ( * v * v - w * w) / / a / v;
vd = w;
}
if(fcmp(r - (v * v - vd * vd) / / a) >= )
t2 = r / v + (v - vd) / a - (v * v - vd * vd) / / a / v;
else
t2 = (sqrt( * a * r + vd * vd) - vd) / a;
printf("%.10f\n", t1 + t2);
return ;
}

5E

找每个点左右分别严格高于这个点的点,有点像并查集的样子

还需要找处在中间的相同高度的点

每个点与左右两个高点及相同高度的点可以互相看到

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll; const int maxn = 1e6 + ;
int height[maxn], l[maxn], r[maxn], same[maxn];
ll ans = ; int main(){
int n;
scanf("%d", &n);
int maxi = -, pos = ;
for(int i = ; i < n; ++i){
scanf("%d", &height[i]);
if(height[i] > maxi){
maxi = height[i];
pos = i;
}
}
rotate(height, height + pos, height + n);
height[n] = maxi;
same[n] = ;
for(int i = n - ; i >= ; --i){
r[i] = i + ;
while(r[i] < n && height[i] > height[r[i]]) r[i] = r[r[i]];
if(r[i] != n && height[i] == height[r[i]]){
same[i] = same[r[i]] + ;
r[i] = r[r[i]];
}
}
for(int i = ; i <= n; ++i){
l[i] = i - ;
while(l[i] && height[i] >= height[l[i]]) l[i] = l[l[i]];
}
for(int i = ; i < n; ++i){
ans += ( + same[i]);
if(l[i] == && r[i] == n) --ans;
}
printf("%I64d\n", ans);
return ;
}

6A

水题

 #include <bits/stdc++.h>
using namespace std; int a, b, c, d; void init(){
int arr[];
cin >> arr[] >> arr[] >> arr[] >> arr[];
sort(arr, arr + );
a = arr[]; b= arr[]; c = arr[]; d = arr[];
}
int main(){
init();
if(a + b > c || a + b > d || a + c > d || b + c > d) puts("TRIANGLE");
else if(a + b == c || a + b == d || a + c == d || b + c == d) puts("SEGMENT");
else puts("IMPOSSIBLE");
return ;
}

6B

两层广搜过的,然而智障了......用一层广搜+set就行了

两层的辣鸡代码....:

 #include <bits/stdc++.h>
using namespace std; const int maxsize = ;
int cx[] = {, -, , }, cy[] = {, , , -};
struct pos{
int x, y;
pos(int xx = , int yy = ): x(xx), y(yy){};
}; char room[maxsize][maxsize];
bool flag[maxsize][maxsize]; int main(){
int n, m;
char color;
cin >> n >> m;
cin.get();
cin >> color;
queue<pos> mainpos;
memset(flag, false, sizeof(flag));
for(int i = ; i < n; ++i)
for(int j = ; j < m; ++j){
cin >> room[i][j];
if(room[i][j] == color){
mainpos.push(pos(i, j));
flag[i][j] = true;
}
}
int ans = ;
while(!mainpos.empty()){
int x = mainpos.front().x, y = mainpos.front().y;
mainpos.pop();
for(int i = ; i < ; ++i){
int nx = x + cx[i], ny = y + cy[i];
if(nx < || n <= nx || ny < || m <= ny || flag[nx][ny] || room[nx][ny] == '.') continue;
++ans;
queue<pos> tpos;
tpos.push(pos(nx, ny));
flag[nx][ny] = true;
char tcolor = room[nx][ny];
while(!tpos.empty()){
int xx = tpos.front().x, yy = tpos.front().y;
tpos.pop();
for(int j = ; j < ; ++j){
int nxx = xx + cx[j], nyy = yy + cy[j];
if(nxx < || n <= nxx || nyy < || m <= nyy || room[nxx][nyy] != tcolor || flag[nxx][nyy]) continue;
flag[nxx][nyy] = true;
tpos.push(pos(nxx, nyy));
}
}
}
}
cout << ans << endl;
return ;
}

一层 + set:

 #include <bits/stdc++.h>
using namespace std; const int maxsize = ;
int cx[] = {, -, , }, cy[] = {, , , -};
struct pos{
int x, y;
pos(int xx = , int yy = ): x(xx), y(yy){};
}; char room[maxsize][maxsize]; int main(){
int n, m;
char color;
cin >> n >> m;
cin.get();
cin >> color;
queue<pos> mainpos;
for(int i = ; i < n; ++i)
for(int j = ; j < m; ++j){
cin >> room[i][j];
if(room[i][j] == color)
mainpos.push(pos(i, j));
}
set<char> ans;
while(!mainpos.empty()){
int x = mainpos.front().x, y = mainpos.front().y;
mainpos.pop();
for(int i = ; i < ; ++i){
int nx = x + cx[i], ny = y + cy[i];
if(nx < || n <= nx || ny < || m <= ny || room[nx][ny] == color || room[nx][ny] == '.') continue;
ans.insert(room[nx][ny]);
}
}
cout << ans.size() << endl;
return ;
}

6C

水题,第一次用deque

 #include <bits/stdc++.h>
using namespace std; int main(){
int n;
cin >> n;
deque<int> chb;
for(int i = ; i < n; ++i){
int tmp;
cin >> tmp;
chb.push_back(tmp);
}
int t1 = chb.front(), ans1 = , t2 = , ans2 = ;
chb.pop_front();
while(!chb.empty()){
if(t1 <= t2){
t1 += chb.front();
++ans1;
chb.pop_front();
}
else{
t2 += chb.back();
++ans2;
chb.pop_back();
}
}
cout << ans1 << " " << ans2 << endl;
return ;
}

6D

不会做.....题解看不懂....... dfs

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = ;
int n, a, b, ans, h[MAXN], hh[MAXN]; bool dfs(int curpos, int time, int hitpos){
if(time == ){
for(int i = ; i <= n; ++i)
if(h[i] >= ) return false;
return true;
}
if(h[curpos] < ) return dfs(curpos+, time, hitpos);
for(int i = min(n-, max(hitpos, max(, curpos))); i <= min(n-, curpos+); ++i){
h[i] -= a; h[i-] -= b; h[i+] -= b;
if(dfs(curpos, time-, i)){
hh[time] = i;
return true;
}
h[i] += a; h[i-] += b; h[i+] += b;
}
return false;
} int main(){
cin >> n >> a >> b;
for(int i = ; i <= n; ++i) cin >> h[i];
for(int i = ; ; ++i){
memset(hh, , sizeof(hh));
if(dfs(, i, )){
cout << i << endl;
for(int j = ; j <= i; ++j)
cout << hh[j] << " ";
return ;
}
}
return ;
}

6E

求最大值最小值差不超过给定值的最长子串

ST表预处理区间最大值最小值,加个二分右边界...

 #include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int n, k;
int data[maxn];
int premin[maxn][], premax[maxn][];
struct tpoint{
int l, r;
tpoint(int _l, int _r): l(_l), r(_r) {};
}; void init_st(){
for(int i = ; i <= n; ++i)
premin[i][] = premax[i][] = data[i];
int k = floor(log(double(n)) / log(2.0));
for(int j = ; j <= k; ++j)
for(int i = n; i >= ; --i)
if(i + (<<(j-)) <= n){
premin[i][j] = min(premin[i][j-], premin[i+(<<(j-))][j-]);
premax[i][j] = max(premax[i][j-], premax[i+(<<(j-))][j-]);
}
} int query_st(int l, int r){
int k = floor(log(double(r-l+)) / log(2.0));
return max(premax[l][k], premax[r-(<<k)+][k]) - min(premin[l][k], premin[r-(<<k)+][k]);
} int check(int i){
int l = i, r = n + ;
while(l < r - ){
int mid = (l + r) >> ;
if(query_st(i, mid) <= k) l = mid;
else r = mid;
}
return l;
} int main(){
scanf("%d %d", &n, &k);
for(int i = ; i <= n; ++i)
scanf("%d", &data[i]);
init_st();
int amount = ;
vector<tpoint> vp;
for(int l = ; l <= n; ++l){
int r = check(l);
int num = r - l + ;
if(num > amount){
vp.clear();
vp.push_back(tpoint(l, r));
amount = num;
}
else if(num == amount) vp.push_back(tpoint(l, r));
}
printf("%d %d\n", amount, vp.size());
for(vector<tpoint>::iterator i = vp.begin(); i != vp.end(); ++i)
printf("%d %d\n", (*i).l, (*i).r);
return ;
}

7A

水题但是有点意思(因为你还是个渣啊~)

记下每一行每一列多少个黑,凑齐8个答案+1,若答案是16就-8

 #include <bits/stdc++.h>
using namespace std; char cb[][];
int cnt[][]; int main(){
ios::sync_with_stdio(false);
int ans = ;
for(int i = ; i < ; ++i)
for(int j = ; j < ; ++j){
cin >> cb[i][j];
if(cb[i][j] == 'B'){
++cnt[i][];
++cnt[][j];
}
if(cnt[i][] == ) ++ans;
if(cnt[][j] == ) ++ans;
}
if(ans == ) ans -= ;
cout << ans << endl;
return ;
}

7B

粗暴地模拟,大概坑都是给我挖的....

 #include <bits/stdc++.h>
using namespace std; const int maxn = ;
int n, k, mem[maxn]; int main(){
int counter = ;
scanf("%d %d", &n, &k);
while(n--){
char s[];
int x;
scanf("%s", s);
if(s[] == 'a' || s[] == 'e'){
scanf("%d", &x);
if(s[] == 'a'){
bool flag = false;
int tmp = ;
for(int i = ; i < k; ++i){
if(mem[i] == ) ++tmp;
else tmp = ;
if(tmp == x){
printf("%d\n", ++counter);
int index = i;
while(tmp--) mem[index--] = counter;
flag = true;
break;
}
}
if(!flag) puts("NULL");
}
else{
bool flag = false;
for(int i = ; i < k; ++i){
if(x == ) break;
if(mem[i] == x){
mem[i] = ;
flag = true;
}
}
if(!flag) puts("ILLEGAL_ERASE_ARGUMENT");
}
}
else{
for(int i = ; i < k; ++i){
if(mem[i] != ){
int j = i;
while(j > && mem[j-] == ) --j;
swap(mem[i], mem[j]);
}
}
}
}
return ;
}

7C

扩展欧几里得解不定方程组

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll; ll ex_gcd(ll a, ll b, ll& x, ll& y){
if(b == ){
x = ;
y = ;
return a;
}
int k = ex_gcd(b, a % b, x, y);
int t = y;
y = x - (a / b) * y;
x = t;
return k;
} int main(){
ios::sync_with_stdio(false);
ll a, b, c, x, y;
cin >> a >> b >> c;
ll k = ex_gcd(a, b, x, y);
c = -c;
if(c % k) cout << "-1" << endl;
else cout << (c / k * x) << " " << (c / k * y) << endl;
return ;
}

7D

字符串两个方向hash判回文+dp

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll; const int maxn = 5e6 + ;
const int mod = 1e9 + ;
const int tmp = ;
char s[maxn];
ll prefix[maxn], suffix[maxn], dp[maxn]; int main(){
gets(s);
for(int i = ; s[i]; ++i){
if(s[i] >= '' && s[i] <= '')
s[i] -= '';
else if(s[i] >= 'a' && s[i] <= 'z')
s[i] -= ('a' - );
else
s[i] -= ('A' - );
}
ll len = strlen(s), base = ;
for(int i = ; i <= len; ++i){
prefix[i] = (prefix[i-] + s[i-] * base) % mod;
base = (base * tmp) % mod;
suffix[i] = (suffix[i-] * tmp + s[i-]) % mod;
}
ll ans = ;
for(int i = ; i <= len; ++i){
if(prefix[i] == suffix[i]){
dp[i] = dp[i>>] + ;
ans += dp[i];
}
}
printf("%I64d\n", ans);
return ;
}

7E

arhgoiawhengiuehgoaijgioj........

8A

水题,用py3写是因为.....懒......

 s = input()
s1 = input()
s2 = input() forw = backw = False
tmp = s.find(s1)
if ~tmp:
if ~s[tmp+len(s1):].find(s2):
forw = True
s = s[::-1]
tmp = s.find(s1)
if ~tmp:
if ~s[tmp+len(s1):].find(s2):
backw = True if forw and backw: print('both')
elif forw: print('forward')
elif backw: print('backward')
else: print('fantasy')

8B

啊啊啊啊啊啊啊手贱啊啊啊啊啊啊啊  真·教育题  谢谢(微笑)

 #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> point;
map<point, int> check;
int cx[] = {, -, , }, cy[] = {, , -, };
int main(){
string s;
cin >> s;
int x = , y = , xx = , yy = ;
++check[point(x, y)];
bool flag = true;
for(int i = ; i < s.size(); ++i){
if(s[i] == 'L') --x;
else if(s[i] == 'R') ++x;
else if(s[i] == 'U') ++y;
else --y;
for(int i = ; i < ; ++i){
int xxx = x + cx[i], yyy = y + cy[i];
if(xxx == xx && yyy == yy) continue;
if(check[point(xxx, yyy)]){
flag = false;
break;
}
}
if(check[point(x, y)]) flag = false;
if(!flag) break;
++check[point(x, y)];
xx = x; yy = y;
}
cout << (flag ? "OK" : "BUG") << endl;
return ;
}

8C

状压dp,不需要绝对固定的顺序,所以每次只要取最前面可取的(line34的break),每次拿一个或两个(最里层for从 j 开始)

 #include <bits/stdc++.h>
using namespace std;
const int MAXN = ;
const int INF = 0x3f3f3f3f;
struct point{
int x, y;
point(){}
point(int xx, int yy): x(xx), y(yy) {}
};
point p[MAXN];
int n, dp[<<MAXN], pre[<<MAXN], dis[MAXN][MAXN], ans[];
inline int calc(point a, point b){
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
int main(){
cin >> p[].x >> p[].y >> n, p[n] = p[];
for(int i = ; i < n; ++i) cin >> p[i].x >> p[i].y;
for(int i = ; i <= n; ++i) for(int j = ; j <= n; ++j) dis[i][j] = calc(p[i], p[j]);
memset(dp, INF, sizeof(dp));
dp[] = ;
for(int i = ; i < (<<n); ++i)
if(dp[i] != INF)
for(int j = ; j < n; ++j)
if(!(i>>j&)){
for(int k = j; k < n; ++k)
if(!(i>>k&)){
int cur = i | (<<j) | (<<k);
int tmp = dp[i] + dis[n][j] + dis[j][k] + dis[k][n];
if(dp[cur] > tmp){
dp[cur] = tmp;
pre[cur] = i;
}
}
break;
}
cout << dp[(<<n)-] << endl << ;
int cnt = ;
for(int i = (<<n)-; i; i = pre[i]){
int tmp = pre[i] ^ i;
ans[cnt++] = ;
for(int j = ; j < n; ++j)
if((<<j)&tmp)
ans[cnt++] = j + ;
}
for(int i = cnt-; ~i; --i) cout << " " << ans[i];
return ;
}

8D

CODEFORCES-PROBLEMSET的更多相关文章

  1. 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: N个人,每个人有pi个物品,每个物品价值为0~49.每次从1~n顺序选当前这个人的物品,如果这个物品的价值&g ...

  2. codeforces.com/problemset/problem/213/C

    虽然一开始就觉得从右下角左上角直接dp2次是不行的,后面还是这么写了WA了 两次最大的并不一定是最大的,这个虽然一眼就能看出,第一次可能会影响第二次让第二次太小. 这是原因. 5 4 32 1 18 ...

  3. http://codeforces.com/problemset/problem/847/E

    E. Packmen time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  4. http://codeforces.com/problemset/problem/594/A

    A. Warrior and Archer time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. http://codeforces.com/problemset/problem/712/D

    D. Memory and Scores time limit per test 2 seconds memory limit per test 512 megabytes input standar ...

  6. http://codeforces.com/problemset/problem/545/D

    D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  7. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  10. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. 【转】Android双向滑动菜单完全解析,教你如何一分钟实现双向滑动特效

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9671609 记得在很早之前,我写了一篇关于Android滑动菜单的文章,其中有一个 ...

  2. DevExpress中GridView Excel下载

    DevExpress中GridView提供了许多Excel下载的方法,如gridView.ExportToExcelOld(sfdExcelDown.FileName); 在修改Bug时,遇到这样问题 ...

  3. 自己动手实现Expression翻译器 – Part Ⅱ

    上一节我们了解了Linq查询大体上是如何运转的,并针对SQL表达式进行建模(DbExpression),这一节的重点在于如何将表达式转换为DbExpression. 可以说只要能生成结构清晰的DbEx ...

  4. 实现基本的CRUD功能

    文] 使用 MVC 5 的 EF6 Code First 入门 系列:实现基本的CRUD功能 2014-04-28 16:29 by Bce, 428 阅读, 0 评论, 收藏, 编辑 英文渣水平,大 ...

  5. 2014.3.6-C语言学习小结

    链表基础: 知识点: 1.链表基础 2.节点的创建和添加 llist_append_node 3.链表的遍历 llist_print_each 4.链表的查找与修改 5.链表的插入与删除 6.链表的销 ...

  6. Python语言在企业级应用上的十大谬误

    英文原文:https://www.paypal-engineering.com/2014/12/10/10-myths-of-enterprise-python/ 翻译原文:http://www.os ...

  7. 代码重构方向原则指导(转载 cnblogs)

    英文原文:Hill Climbing (Wonkish)   重构是一种对软件进行修改的行为,但它并不改变软件的功能特征,而是通过让软件程序更清晰,更简洁和更条理来改进软件的质量.代码重构之于软件,相 ...

  8. 用来代替本机IP的万能IP:127.0.0.1

    用来代替本机IP的通用IP:127.0.0.1

  9. poj1269

    基础题,直线间关系 #include <iostream> #include <math.h> #include <iomanip> #define eps 1e- ...

  10. 【总结】AngularJs学习总结

    应项目的需要,一个月之前开始做WebComponents.Javascript MVC框架的技术调研,由于重点是想做组件化,所以就没有考虑Backbone(去年就小试牛刀,太难用了)及其他的mvc框架 ...