题解

1323 条题解

  • -1
    @ 2017-08-16 18:26:54

    C++,我用个二进制吧。。。
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    int main()
    {
    int a,b,s=0,s1=0,i=0,na=0,nb=0;
    cin>>a>>b;
    if(a<=0) na=1,a*=-1;
    while(a!=0)
    {
    if(a%2!=0)
    s+=pow(2,a%2*i);
    a/=2;
    i++;
    }
    i=0;
    if(na==1) s*=-1;
    if(b<=0) nb=1,b*=-1;
    while(b!=0)
    {
    if(b%2!=0)
    s1+=pow(2,b%2*i);
    b/=2;
    i++;
    }
    if(nb==1) s1*=-1;
    cout<<s+s1;;
    return 0;
    }

  • -1
    @ 2017-08-03 18:41:04

    #include<cstdio>
    //调用头文件。
    using namespace std;
    int main()
    {
    int a,b;//定义a,b。
    scanf("%d%d",&a,&b);//通过scanf格式化输入。
    printf("%d",a+b);//直接输出表达式即可
    return 0;
    }

  • -1
    @ 2017-07-24 19:22:06

    import java.io.*;
    import java.util.Scanner;

    public class Main {
    public static void main(String[] args) throws IOException {
    Scanner cin = new Scanner(System.in);
    int a = cin.nextInt();
    int b = cin.nextInt();
    System.out.println(a + b);
    }
    }

  • -1
    @ 2017-07-22 20:54:52

    #inlcude<iostream>
    using namespace std;
    int main()
    {
    int A,B;
    cin>>A>>B;
    cout<<A+B<<endl;
    return 0;
    }

  • -1
    @ 2017-05-14 11:15:00

    #include<stdio.h>
    int main()
    {
    int a,b,c;
    scanf("%d %d",&a,&b);
    c=a+b;
    printf("%d",c);
    return 0;
    }

  • -1
    @ 2017-04-10 16:16:23

    include <iostream>

    include <cstring>

    using namespace std;

    int low_bit (int a) {
    return a & (-a);
    }

    int main () {
    int n = 2, m = 1;
    int ans[m + 1];
    int a[n + 1], c[n + 1], s[n + 1];
    int o = 0;

    memset (c, 0, sizeof(c));

    s[0] = 0;

    for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
    c[i] = s[i] - s[i - low_bit(i)];
    }

    for (int i = 1; i <= m; i++) {
    int q = 2;
    {
    int x = 1, y = 2;
    int s1 = 0, s2 = 0, p = x - 1;

    while (p > 0) {
    s1 += c[p];
    p -= low_bit(p);
    }

    p = y;

    while (p > 0) {
    s2 += c[p];
    p -= low_bit(p);
    }

    o++;

    ans[o] = s2 - s1;
    }
    }

    for (int i = 1; i <= o; i++)
    cout << ans[i] << endl;

    return 0;
    }

  • -1
    @ 2017-03-14 17:40:18

    var a,b:longint;
    begin
    readln(a,b);
    writeln(a+b);
    end.

  • -1
    @ 2017-03-12 11:37:25
    #include<iostream>
    using namespace std;
    int Plus(int a, int b)
    {
        return a + b;
    }
    int main()
    {
        int a, b;
        cin >> a >> b;
        cout << Plus(a, b);
        return 0;
    }
    
  • -1
    @ 2017-03-11 17:26:33

    #include <iostream>
    using namespace std;

    int main() {
    int a,b;
    cin>>a>>b;
    cout<<a+b;
    return 0;
    }

  • -1
    @ 2017-03-10 21:09:18

    #include <stdio.h>
    #include <iostream>
    using namespace std;
    int main()
    {
    int a,b,c;
    cin>>a;
    cin>>b;
    c=a+b;
    cout<<c<<endl;
    return 0;
    }

  • -1
    @ 2017-03-05 12:02:25

    main函数自递归和位运算

    #include<bits/stdc++.h>
    int main(int a,int b,int k)
    {
        if (k) scanf("%d%d",&a,&b);
        printf("%d",b==0?a:main(a^b,(a&b)<<1,0));
        exit(0);
    }
    
  • -1
    @ 2017-03-04 16:26:58
    #include<iostream>
    #include<iomanip>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    int m,n;
    int main()
    {
        cin>>n>>m;
        cout<<n+m;
        return 0;               
    }
    
  • -1
    @ 2017-02-20 19:47:50

    #include <stdio.h>
    int main()
    {
    int x,y;
    scanf("%d %d",&x,&y);
    printf("%d",x+y);
    return 0;
    }

  • -1
    @ 2017-02-15 16:26:57

    #include <cstdio>
    int main()
    {
    int a;
    int b;
    scanf("%d %d",&a,&b);
    printf("%d",a+b);
    return 0;
    }

  • -1
    @ 2017-02-08 16:18:59
    //C Code
    #include<stdio.h>
    int a,b;
    int main(){
      scanf("%d%d",&a,&b);
      printf("%d",a+b);
    }
    
    //Cpp Code
    #include<cstdio>
    int a,b;
    int main(){
      scanf("%d%d",&a,&b);
      printf("%d",a+b);
    }
    
    //Pascal Code
    Var
      A,B:Integer;
    Begin
      Readln(A,B);
      Writeln(A+B);
    End.
    
  • -1
    @ 2017-02-07 22:42:50

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #include<cstdlib>
    #include<set>
    #include<map>
    #include<cctype>
    #include<string>
    #define debug(x) cerr << #x << " = " << x << endl
    #define LL long long
    #define ULL unsigned long long
    #define MAXN 100010
    using namespace std;
    inline int read(){
    int x = 0, f = 1;
    char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    return x * f;
    }

    const int inf = 1e9 + 7;
    int n, Q;
    struct Node{
    int val, size, cnt;
    Node *pre, *ch[2];
    void update(){
    size = ch[0]->size + ch[1]->size + cnt;
    }
    int get_wh(){
    return pre->ch[0] == this ? 0 : 1;
    }
    void set_ch(int wh, Node *child);
    } pool[MAXN], *null, *root;

    void Node::set_ch(int wh, Node *child){
    ch[wh] = child;
    if(child != null) child->pre = this;
    update();
    }

    int top = 0;

    inline Node *get_new(int val){
    Node *now = pool + ++top;
    now->size = now->cnt = 1;
    now->val = val;
    now->pre = now->ch[0] = now->ch[1] = null;
    return now;
    }

    inline void rotate(Node *&now){
    Node *old_fa = now->pre, *grand = now->pre->pre;
    int wh = now->get_wh();
    old_fa->set_ch(wh, now->ch[wh ^ 1]);
    now->set_ch(wh ^ 1, old_fa);
    now->pre = grand;
    if(grand != null)
    grand->ch[grand->ch[0] == old_fa ? 0 : 1] = now;
    }

    inline void splay(Node *now, Node *tar){
    for(; now->pre != tar; rotate(now))
    if(now->pre->pre != tar)
    now->get_wh() == now->pre->get_wh() ? rotate(now->pre) : rotate(now);
    if(tar == null) root = now;
    }

    void insert(int val){
    Node *last = null, *now = root;
    Node *newnode = get_new(val);
    while(now != null){
    last = now;
    if(val == now->val){
    now->cnt++, now->size++;
    splay(now, null);
    return;
    }
    else if(val < now->val)
    now = now->ch[0];
    else
    now = now->ch[1];
    }
    if(last == null)
    root = newnode;
    else{
    if(val < now->val)
    last->set_ch(0, newnode);
    else
    last->set_ch(1, newnode);
    splay(newnode, null);
    }
    }

    inline Node *find(int val){
    Node *now = root;
    while(now != null){
    if(now->val == val)
    break;
    else if(now->val < val)
    now = now->ch[0];
    else
    now = now->ch[1];
    }
    if(now != null) splay(now, null);
    return now;
    }

    void del(int val){
    Node *now = find(val);
    if(now == null) return;
    if(now->cnt > 1){
    now->cnt--;
    now->size--;
    return;
    }
    if(now->ch[0] == null && now->ch[1] == null)
    root = null;
    else if(now->ch[0] == null){
    now->ch[1]->pre = null; root = now->ch[1];
    }
    else if(now->ch[1] == null){
    now->ch[0]->pre = null; root = now->ch[0];
    }
    else{
    Node *_ = now->ch[0];
    while(_->ch[1] != null) _ = ->ch[1];
    splay(
    , now);
    _->set_ch(1, now->ch[1]);
    _->pre = null;
    root = _;
    }
    }

    inline int pre(int val){
    Node *now = root;
    int ans = -inf;
    while(now != null){
    if(now->val < val){
    ans = max(ans, now->val);
    now = now->ch[1];
    }
    else
    now = now->ch[0];
    }
    return ans;
    }

    inline int nxt(int val){
    Node *now = root;
    int ans = inf;
    while(now != null){
    if(now->val > val){
    ans = min(ans, now->val);
    now = now->ch[0];
    }
    else
    now = now->ch[1];
    }
    return ans;
    }

    inline int get_rank(int val){
    Node *now = root;
    int left = 0;
    while(now != null){
    if(val == now->val){
    int ans = left + now->ch[0]->size + 1;
    splay(now, null);
    return ans;
    }
    else if(val < now->val)
    now = now->ch[0];
    else{
    left += now->ch[0]->size + now->cnt;
    now = now->ch[1];
    }
    }
    return -1;
    }

    inline int kth(int k){
    Node *now = root;
    int left = 0;
    while(now != null){
    int _ = left + now->ch[0]->size;
    if(_ + 1 <= k && k <= _ + now->cnt){
    splay(now, null);
    return now->val;
    }
    else if(k <= _)
    now = now->ch[0];
    else
    left += now->ch[0]->size + now->cnt, now = now->ch[1];
    }
    return -1;
    }

    int main(){
    null = pool;
    null->size = null->cnt = null->val = 0;
    null->ch[0] = null->ch[1] = null->pre = null;
    root = null;
    Q = read();
    while(Q--){
    int opt = read(), x = read();
    switch(opt) {
    case 1:
    insert(x);
    break;

    case 2:
    del(x);
    break;
    case 3:
    cout << get_rank(x) << endl;
    break;
    case 4:
    cout << kth(x) << endl;
    break;
    case 5:
    cout << pre(x) << endl;
    break;
    case 6:
    cout << nxt(x) << endl;
    break;
    }
    }
    return 0;
    }

  • -1
    @ 2017-02-06 17:16:04

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<set>
    #include<map>
    #include<cmath>
    #include<string>
    #include<cctype>
    #define debug(x) cerr << #x << " = " << x << endl
    #define LL long long
    #define MAXN 210
    using namespace std;
    int read(){
    int x = 0, f = 1;
    char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch -'0';
    return x * f;
    }

    const int inf = 1e9 + 7;
    int n, r[MAXN], s, t;
    struct CCM{int t, ne, l;
    void clear(){
    ne = -1;
    }
    } e[MAXN];
    int v[MAXN], num = -1;
    int dep[MAXN], cur[MAXN];
    int ans;

    void add(int x, int y, int l){
    e[++num].t = y, e[num].ne = v[x], e[num].l = l, v[x] = num;
    }

    int q[MAXN * MAXN];
    bool bfs(){
    memset(dep, 0, sizeof dep);
    int head = 0, tail = 1;
    q[1] = s, dep[s] = 1;
    for(int i = 1; i <= n; i++) cur[i] = v[i];
    int x;
    while(head < tail){
    x = q[++head];
    for(int i = v[x]; i != -1; i = e[i].ne)
    if(!dep[e[i].t] && e[i].l){
    dep[e[i].t] = dep[x] + 1;
    q[++tail] = e[i].t;
    }
    }
    if(dep[t]) return 1;
    return 0;
    }

    int dfs(int x, int t, int lim){
    if(!lim || x == t) return lim;
    int flow = 0, f;// debug(lim);
    for(int i = cur[x]; i != -1; i = e[i].ne){
    cur[x] = i; //if(x == s) debug(e[i].l);
    if(dep[e[i].t] == dep[x] + 1 && (f = dfs(e[i].t, t, min(e[i].l, lim)))){
    flow += f;
    lim -= f;
    e[i].l -= f;
    e[i ^ 1].l += f;
    if(!lim) break;
    }
    }
    return flow;
    }

    int idx(int x){
    return n + x;
    }

    int main(){
    memset(v, -1, sizeof v);
    for(int i = 1; i <= MAXN; i++) e[i].clear();
    n = read();
    s = 2 * n + 1, t = 2 * n + 2;
    for(int i = 1; i <= n; i++) r[i] = read();
    for(int i = 1, x; i <= n; i++)
    for(int j = 1; j <= r[i]; j++)
    x = read(), add(i, idx(x), inf), add(idx(x), i, 0);
    for(int i = 1; i <= n; i++)
    add(s, i, 1), add(i, s, 0), add(idx(i), t, 1), add(t, idx(i), 0);
    for(int i = v[s]; i != -1; i = e[i].ne) debug(e[i].l);
    while(bfs()) ans += dfs(s, t, inf);
    cout << ans << endl;
    return 0;
    }

  • -1
    @ 2017-01-31 10:32:00

    #include <iostream>
    using namespace std;
    int main()
    {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
    }

  • -1
    @ 2017-01-25 11:23:57

    走一波面向对象的A+B。
    <pre>
    #include <bits/stdc++.h>

    using namespace std;

    class Something
    {
    friend istream & operator>>(istream & is, Something & as);
    friend ostream & operator<<(ostream & os, Something & as);
    public:
    int a, b;
    int sum(int x, int y);
    Something & operator+(int z);
    Something & operator+(Something b);

    };

    istream & operator>>(istream & is, Something & as)
    {
    is >> as.a;
    return is;
    }

    ostream & operator<<(ostream & os, Something & as)
    {
    os << as.a;
    return os;
    }

    int Something::sum(int x, int y)
    {
    return x + y;
    }

    Something & Something::operator+(int z)
    {
    a += z;
    return *this;
    }

    Something & Something::operator+(Something b)
    {
    a += b.a;
    return *this;
    }

    int main(int argc, char const *argv[])
    {
    Something sd, st;
    cin >> sd >> st;
    cout << sd + st;
    return 0;
    }
    </pre>

  • -1
    @ 2017-01-22 14:12:30

    #include<iostream> //基础头文件
    using namespace std; //自定义函数
    int main() //输入命令
    {
    int a,b=0,n=2; //1.定义a,用来输入两个数。 2.定义b,用来计数输入的两个数。 3.定义n,用来循环2次。
    for(int i=1;i<=n;i++) //开始循环,循环次数n,n=2
    {
    cin>>a; //输入a;经循环共两次
    b+=a; //计数,为了方便统计,输出时直接把b输出。
    } //循环结束。
    cout<<b; //输出循环后的结果。
    return 0;
    }

信息

ID
1000
难度
9
分类
(无)
标签
(无)
递交数
74450
已通过
28496
通过率
38%
被复制
223