A模拟
只需要对项目a和项目b进行选择
假设此时为t秒,选择项目a和b
如果先选项目a
那么时间为
\(a.a+a.b*t+(a.a+a.b*t+t)*b.b + b.a\)
如果先选项目b
那么时间为
\(b.a+b.b*t+(b.a+b.b*t+t)*a.b+a.a\)
相约之后为
\(a.a*b.b\)和\(b,a*a.b\)
那么按照这个排序即可
注意开long long即可
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <vector> #define ll long long const int maxn = 1e5+5; const int inf = 0x3f3f3f3f; const double eps = 1e-5; const ll mod = 365 * 24 * 60 * 60; using namespace std; struct node{ ll a,b; }e[maxn]; bool cmp(node a,node b){ return a.a * b.b < b.a * a.b; } int main(){ int n; while(~scanf("%d",&n)){ if(n==0)break; for(int i=0;i<n;i++)scanf("%lld%lld",&e[i].a,&e[i].b); sort(e,e+n,cmp); ll ans = 0; for(int i=0;i<n;i++){ ans = (ans * e[i].b + e[i].a + ans) % mod; } printf("%lld\n",ans); } return 0; }
I水题
求出所有数字的平方和即可
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <cmath> const int maxn = 1e5+5; const int inf = 0x3f3f3f3f; const double eps = 1e-5; using namespace std; int main(){ int n; while(cin>>n){ if(n==0)break; int sum = 0; int x; for(int i=0;i<n;i++){ cin>>x; sum += pow(x,2); } cout<<sum<<endl; } return 0; }
K超级大模拟
耐心算出规律即可
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <vector> const int maxn = 1e5+5; const int inf = 0x3f3f3f3f; const double eps = 1e-5; using namespace std; struct node{ int s;//速度 int t;//转弯的时间 char c;//方向 int x,y;//坐标 }tom,jerry; int k; int n; void print(){ printf("%d %d\n",tom.x,tom.y); printf("%d %d\n",jerry.x,jerry.y); } void change(node &a,int i){//检测是否左转 if(i % a.t == 0){ switch(a.c){ case 'W':a.c = 'S';break; case 'E':a.c = 'N';break; case 'S':a.c = 'E';break; case 'N':a.c = 'W';break; } } } bool check(){//检测是否需位于同一个点且交换方向 if(tom.x == jerry.x && tom.y == jerry.y){ swap(tom.c,jerry.c); return true; } return false; } void move(node &a){ if(a.c == 'W'){//左前进 if(a.y > a.s){ a.y -= a.s; }else if(a.y <= a.s && a.s <= n-1+a.y){ a.y = a.s - (a.y - 2); a.c = 'E'; }else{ a.y = a.s - a.y; } }else if(a.c == 'E'){//右前进 if(a.y + a.s <= n){ a.y += a.s; }else if(a.s >= n-a.y && a.s <= n-a.y+n-1){ a.y = 2 * n - a.y - a.s; a.c = 'W'; }else{ a.y = a.s - (2*(n-1)-a.y); } }else if(a.c == 'N'){//上前进 if(a.x > a.s){//不换方向 a.x -= a.s; }else if(a.x <= a.s && a.s <= n-1+a.x){//只换一次方向 a.x = a.s - (a.x - 2); a.c = 'S'; }else{//换两次方向 a.x = a.s - a.x; } }else if(a.c == 'S'){//下前进 if(a.x + a.s <= n){ a.x += a.s; }else if(a.s >= n-a.x && a.s <= n-a.x+n-1){ a.x = 2 * n - a.x - a.s; a.c = 'N'; }else{ a.x = a.s - (2*(n-1)-a.x); } } } void getans(){//先运到,判断是否在同一点然后交换方向,再判断转弯 for(int i=1;i<=k;i++){ move(tom); move(jerry); bool xx = check(); if(xx==true)continue; change(tom,i); change(jerry,i); } print(); } void init(){//初始位置和削弱速度 tom.x = tom.y = 1; jerry.x = jerry.y = n; tom.t = tom.t % (2 * (n - 1)); jerry.t = jerry.t % (2 * (n - 1)); } int main(){ while(cin>>n){ if(n==0)break; cin>>tom.c>>tom.s>>tom.t; cin>>jerry.c>>jerry.s>>jerry.t; init(); cin>>k; getans(); } return 0; }