CodeForces727C

CodeForces727C
人生第一道交互,相信大多数人第一眼都是解方程吧...其实这么做就行了.
不过不能对所有的\(n\)个方程直接求解,这样高消就没了.
我们发现,只需要问出前三个数字的方程,后面每个数字都询问和前三个数字中某一个的和再相减就行了.
前三个数字需要三次询问,后面每个数字都需要一次询问,正好\(n\)次询问.
吐槽:一开始做交互题,不知道要\(fflush(stdout)\),连续出了好几次\(Idleness \: limit \: exceeded\),后来去查了一下才知道要\(fflush\).
\(Code:\)

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
#define per(i,a,b) for (int i = a ; i >= b ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>
#define int long long
#define pb push_back

using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;

template < class T >
    inline T read () {
        T x = 0 , f = 1 ; char ch = getchar () ;
        while ( ch < '0' || ch > '9' ) {
            if ( ch == '-' ) f = - 1 ;
            ch = getchar () ;
        }
       while ( ch >= '0' && ch <= '9' ) {
            x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
            ch = getchar () ;
       }
   return f * x ;
}

template < class T >
    inline void write (T x) {
       static T stk[100] , top = 0 ;
       if ( x == 0 ) { putchar ('0') ; return ; }
       if ( x < 0 ) { x = - x ; putchar ( '-' ) ; }
       while ( x ) { stk[++top] = x % 10 ; x /= 10 ; }
       while ( top ) { putchar ( stk[top--] + '0' ) ; }
       putchar ('\n') ;
    }

const int N = 1e5 + 100 ;

int n , sum1 , sum2 , sum3 , v[N] ;

signed main (int argc , char * argv[]) {
    n = rint () ;
    printf ("? 1 2\n") ; fflush(stdout) ; sum1 = rint () ;
    printf ("? 2 3\n") ; fflush(stdout) ; sum2 = rint () ;
    printf ("? 1 3\n") ; fflush(stdout) ; sum3 = rint () ;
    v[1] = ( sum1 + sum3 - sum2 ) >> 1 ;
    v[2] = sum1 - v[1] ; v[3] = sum3 - v[1] ;
    rep ( i , 4 , n ) {
        printf ("? 1 %lld\n" , i ) ;
        fflush(stdout) ; sum1 = rint () ;
        v[i] = sum1 - v[1] ;
    }
    printf ("! ") ;
    rep ( i , 1 , n ) printf ("%lld " , v[i] ) ;
    return 0 ;
}

posted @ 2019-09-06 08:45  Phecda  阅读(137)  评论(0编辑  收藏  举报

Contact with me