题解

1328 条题解

  • -2
    @ 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;
    }

  • -2
    @ 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;
    }

  • -2
    @ 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.
    
  • -2
    @ 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;
    }

  • -2
    @ 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;
    }

  • -2
    @ 2016-08-01 21:25:10
    #include <assert.h>
    #include <errno.h>
    #include <iostream>
    #include <limits.h>
    #include <locale.h>
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <wchar.h>
    #include <wctype.h>
    #include <algorithm>
    #include <bitset>
    #include <cctype>
    #include <cerrno>
    #include <clocale>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <limits>
    #include <list>
    #include <map>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #define Plus cout<<a+b
    #define Cin cin>>a>>b
    #define Int int a,b 
    #define wo_233 return 0
    using namespace std;
    int main()
    {
        Int;
        Cin;
        Plus;
        wo_233;
    }
    
  • -2
    @ 2016-08-01 21:23:42

    #include <assert.h>
    #include <errno.h>
    #include <iostream>
    #include <limits.h>
    #include <locale.h>
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <wchar.h>
    #include <wctype.h>
    #include <algorithm>
    #include <bitset>
    #include <cctype>
    #include <cerrno>
    #include <clocale>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <limits>
    #include <list>
    #include <map>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #define Plus cout<<a+b
    #define Cin cin>>a>>b
    #define Int int a,b
    #define wo_233 return 0
    using namespace std;
    int main()
    {
    Int;
    Cin;
    Plus;
    wo_233;
    }

  • -2
    @ 2016-08-01 21:20:40

    #include <assert.h>
    #include<iostream>
    #include <errno.h>
    #include <limits.h>
    #include <locale.h>
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <wchar.h>
    #include <wctype.h>
    #include <algorithm>
    #include <bitset>
    #include <cctype>
    #include <cerrno>
    #include <clocale>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <limits>
    #include <list>
    #include <map>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #define boom return
    #define _233 int
    #define hh cin
    #define _2333 for
    using namespace std;
    int dfs(int x,int y)
    {

    if(1)
    boom y==0?x:dfs(x+1,y-1);

    }
    int main()
    {
    _233 a,b,ans=dfs(0,0);
    hh>>a>>b;
    ans=dfs(a,b);
    int nums[1010],lon=0 ;
    while(ans>0)
    {
    nums[++lon]=ans%10;
    ans/=10;
    }
    int num[1010];
    memset(num,dfs(0,0),sizeof(num));
    _2333(int j=1;j<=lon;j++)
    {
    num[lon-j+1]=nums[j];
    }
    _2333(int k=1;k<=lon;k++)
    cout<<num[k];
    dfs(1,1);
    boom 0;
    }

  • -2
    @ 2014-12-19 16:36:15

    #include<iostream>
    using namespace std;

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

  • -2
    @ 2014-12-06 13:28:10

    ###略有难度。。。啊哈哈哈哈哈###
    ##高精度##
    测试数据 #0: Accepted, time = 0 ms, mem = 300 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 300 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 300 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 296 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 296 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 300 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 296 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 296 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 300 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 300 KiB, score = 10
    Accepted, time = 0 ms, mem = 300 KiB, score = 100

    #/*代码*/#
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <queue>
    using namespace std;

    int a[1002],b[1002],c[2005],L,L1,L2;
    char str1[1002],str2[1002];
    int main(){
    cin>>str1>>str2;
    L1=strlen(str1);
    L2=strlen(str2);
    L=(max(L1,L2));
    for (int i=0;i<L1;i++) a[i]=str1[L1-i-1]-'0';
    for (int i=0;i<L2;i++) b[i]=str2[L2-i-1]-'0';
    for (int i=0;i<L;i++) c[i]=a[i]+b[i];
    for (int i=0;i<L;i++)
    if (c[i]>=10) c[i+1]++,c[i]-=10;
    if (c[L]!=0)
    for (int i=L;i>=0;i--) cout<<c[i];
    else for (int i=L-1;i>=0;i--)
    cout<<c[i];
    return 0;
    }

  • -3
    @ 2017-07-22 20:54:03

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

  • -3
    @ 2017-07-21 17:25:43

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

  • -3
    @ 2017-07-21 17:25:10

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

  • -3
    @ 2017-07-21 14:48:04

    不愧是vijos最难的题
    写法千变万化,难以捉摸,各路英雄都给出了强大的解法
    #include <bits/stdc++.h>
    #include <time.h>
    using namespace std;
    int main()
    {
    srand((unsigned)time(NULL));
    int a,b,s;
    scanf ("%d%d",&a,&b);
    for (;;)
    {
    s=rand()%(a+b)+1;
    if (s==a+b) {
    printf ("%d",s);
    break;
    }
    }
    }
    来道随机化解法

  • -3
    @ 2006-03-15 16:27:26

    无语...........

  • -3
    @ 2006-03-06 22:13:32

    唉.......每个online judge 第一题都是这个,汗.......

  • -3
    @ 2006-02-11 20:11:01

    没什么好说的了。。。。。。

  • -3
    @ 2006-01-26 09:08:37

    此题实质上非常复杂 全面考察到了数学史和计算机史 经典代数 常用计算与输入输出等等等等知识点

    考虑到题目的所有可能性 我们应当从计算机存储的二进制的角度来逐步考虑数的表示 以字节计数,采用多字节合用的方式表示一个大整数如今已经是高级程序语言编译器轻松可以达到的目标 可是为了加强对计算机计数的了解 此题可以考虑仍以最原始的方式进行计算——并且考虑最终将二进制数转变为十进制输出的全部过程 期间还考察了对ASCII码的熟悉程度

    此题实在经典 乃居家旅行必备之良题

  • -3
    @ 2006-01-23 15:36:00

    我们同学的程序什么问题也没有

    但是超时....狂晕...

  • -4
    @ 2021-08-13 19:19:16

    #include<bits/stdc++.h>
    using namespace std;
    signed main() {
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d",a+b);
    return 0;
    }

信息

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