头像

Value




离线:1个月前


最近来访(20)
用户头像
Escort
用户头像
安璃晴
用户头像
constintnb
用户头像
月亮守护者
用户头像
_N
用户头像
异类_5
用户头像
GGGGG
用户头像
Jack_FuDan
用户头像
不瘦下去不改名字
用户头像
Æccêleγatσr
用户头像
18203169320
用户头像
@@-@
用户头像
Once.
用户头像
cs.s
用户头像
小滕啊
用户头像
冰菓
用户头像
zombotany
用户头像
潮鸣
用户头像
995740977

活动打卡代码 AcWing 84. 求1+2+…+n

Value
7个月前
class Solution {
public:
    int getSum(int n) {
        return (long long) n * (n + 1) / 2;
    }
};


活动打卡代码 AcWing 3237. 中间数

Value
8个月前
#include <iostream>
using namespace std;
const int N = 1010;
bool flag[N];
int s[N];
int main(){
    int n;  cin >> n;
    for(int i = 0; i < n; i ++ ){
        int t;  cin >> t;
        s[t] ++ ;
        flag[t] = true;
    }
    for(int i = 0; i < N; i ++ )    s[i] += s[i - 1];
    int res = -1;
    for(int i = 0; i < N; i ++ ){
        if(!flag[i])    continue;
        if(s[i - 1] == s[N - 1] - s[i]){
            res = i;
            break;
        } 
    }
    cout << res << endl;
    return 0;
}



Value
8个月前
#include <iostream>
using namespace std;
const int N = 1010;
bool flag[N];
int s[N];
int main(){
    int n;  cin >> n;
    for(int i = 0; i < n; i ++ ){
        int t;  cin >> t;
        s[t] ++ ;
        flag[t] = true;
    }
    for(int i = 0; i < N; i ++ )    s[i] += s[i - 1];
    int res = -1;
    for(int i = 0; i < N; i ++ ){
        if(!flag[i])    continue;
        if(s[i - 1] == s[N - 1] - s[i]){
            res = i;
            break;
        } 
    }
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 3228. 俄罗斯方块

Value
8个月前
#include <iostream>
using namespace std;
const int N = 30;
int graph[N][N];
int t[4][4];
bool check(int row, int col){
    for(int i = 0; i < 4; i ++ ){
        for(int j = 0; j < 4; j ++ ){
            if(i + row >= 15 && t[i][j] == 1)   return true;
            if(graph[i + row][j + col] && t[i][j])  return true;
        }
    }
    return false;
}
int main(){
    for(int i = 0; i < 15; i ++ )
        for(int j = 0; j < 10; j ++ )
            cin >> graph[i][j];
    for(int i = 0; i < 4; i ++ )
        for(int j = 0; j < 4; j ++ )
            cin >> t[i][j];

    int col;    cin >> col;
    col -- ;
    int k = 1;
    while(k < 15){
        if(check(k, col))   break;
        k ++ ;
    }
    k -- ;
    for(int i = k; i < k + 4; i ++ ){
        for(int j = col; j < col + 4; j ++ )
            graph[i][j] = t[i - k][j - col] == 0 ? graph[i][j] : 1;
    }
    for(int i = 0; i < 15; i ++ ){
        for(int j = 0; j < 10; j ++ ){
            cout << graph[i][j] << ' ';
        }
        cout << endl;
    }
    return 0;
}



Value
8个月前
#include <iostream>
using namespace std;
const int N = 30;
int graph[N][N];
int t[4][4];
bool check(int row, int col){
    for(int i = 0; i < 4; i ++ ){
        for(int j = 0; j < 4; j ++ ){
            if(i + row >= 15 && t[i][j] == 1)   return true;
            if(graph[i + row][j + col] && t[i][j])  return true;
        }
    }
    return false;
}
int main(){
    for(int i = 0; i < 15; i ++ )
        for(int j = 0; j < 10; j ++ )
            cin >> graph[i][j];
    for(int i = 0; i < 4; i ++ )
        for(int j = 0; j < 4; j ++ )
            cin >> t[i][j];

    int col;    cin >> col;
    col -- ;
    int k = 1;
    while(k < 15){
        if(check(k, col))   break;
        k ++ ;
    }
    k -- ;
    for(int i = k; i < k + 4; i ++ ){
        for(int j = col; j < col + 4; j ++ )
            graph[i][j] = t[i - k][j - col] == 0 ? graph[i][j] : 1;
    }
    for(int i = 0; i < 15; i ++ ){
        for(int j = 0; j < 10; j ++ ){
            cout << graph[i][j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


活动打卡代码 AcWing 3227. 折点计数

Value
8个月前
#include <iostream>
using namespace std;
int main(){
    int n;  cin >> n;
    int status = 0, res = 0;
    int pre = -1;
    for(int i = 0; i < n; i ++ ){
        int tmp;    cin >> tmp;
        if(pre == -1) pre = tmp;
        else if(pre > tmp){
            if(status){
                if(status > 0)  res ++ , status = -1;
            }else   status = -1;
            pre = tmp;
        }else if(pre < tmp){
            if(status){
                if(status < 0)  res ++ , status = 1;
            }else   status = 1;
            pre = tmp;
        } 
    }
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 3257. 跳一跳

Value
8个月前
#include <iostream>
using namespace std;
int main(){
    int score = 0, t;
    int pre = 0;
    while(cin >> t && t){
        if(t == 1)  pre = 1, score += t;
        else{
            if(pre == 1)    pre = 2, score += 2;
            else    pre = pre + 2, score += pre;
        }
    }
    cout << score << endl;
    return 0;
}

作者:Value
链接:https://www.acwing.com/solution/content/38269/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


活动打卡代码 AcWing 3263. 买菜

Value
8个月前
#include <iostream>
#define x first
#define y second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 2e3 + 10;
pii a[N], b[N];
ll cmp(int i, int j){
    if(a[i].x <= b[j].x && b[j].x <= a[i].y)    return min(a[i].y, b[j].y) - b[j].x;
    else if(a[i].x >= b[j].x && a[i].x <= b[j].y)   return min(b[j].y, a[i].y) - a[i].x;
    return 0;
}
int main(){
    int n;  cin >> n;
    for(int i = 0; i < n; i ++ )    cin >> a[i].x >> a[i].y;
    for(int i = 0; i < n; i ++ )    cin >> b[i].x >> b[i].y;
    ll res = 0;
    for(int i = 0; i < n; i ++ )
        for(int j = 0; j <= n; j ++ )
            res += cmp(i, j);
    cout << res << endl;
    return 0;
}



Value
8个月前
#include <iostream>
#define x first
#define y second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 2e3 + 10;
pii a[N], b[N];
ll cmp(int i, int j){
    if(a[i].x <= b[j].x && b[j].x <= a[i].y)    return min(a[i].y, b[j].y) - b[j].x;
    else if(a[i].x >= b[j].x && a[i].x <= b[j].y)   return min(b[j].y, a[i].y) - a[i].x;
    return 0;
}
int main(){
    int n;  cin >> n;
    for(int i = 0; i < n; i ++ )    cin >> a[i].x >> a[i].y;
    for(int i = 0; i < n; i ++ )    cin >> b[i].x >> b[i].y;
    ll res = 0;
    for(int i = 0; i < n; i ++ )
        for(int j = 0; j <= n; j ++ )
            res += cmp(i, j);
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 3262. 卖菜

Value
8个月前
#include <iostream>
using namespace std;
const int N = 1010;
int a[N];
int main(){
    int n;  cin >> n;
    for(int i = 0; i < n; i ++ )    scanf("%d", &a[i]);
    for(int i = 0; i < n; i ++ ){
        if(i == 0)  cout << (a[1] + a[0]) / 2;
        else if(i == n - 1) cout << (a[n - 2] + a[i]) / 2;
        else    cout << (a[i - 1] + a[i] + a[i + 1]) / 3;
        if(i == n - 1)  cout << endl;
        else    cout << ' ';
    }
    return 0;
}