首页 > 其他分享 >CSU 1810 Reverse

CSU 1810 Reverse

时间:2022-11-09 19:33:20浏览次数:44  
标签:1810 Reverse int res CSU const mod include define


Description


1 d 2…d n



1…d i-1 d j d j-1…d i d j+1 d j+2…d n.



Bobo would like to find





9+7).


Input


The input contains at most 30 sets. For each set:


5).


1 d 2…d n (0≤d i≤9).


Output


For each set, an integer denotes the result.


Sample Input

2
12
3
012
10
0123456789

Sample Output

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int T, n;
LL L[N], l[N], r[N], R[N], a[N];
char s[N];

int main()
{
while (scanf("%d", &n) != EOF)
{
scanf("%s", s + 1);
rep(i, 1, n) a[i] = s[i] - '0';
l[0] = L[0] = R[0] = r[0] = 0;
rep(i, 1, n)
{
l[i] = (l[i - 1] + a[i]) % mod;
L[i] = (L[i - 1] + a[i] * i) % mod;
r[i] = (r[i - 1] + a[n - i + 1]) % mod;
R[i] = (R[i - 1] + a[n - i + 1] * i) % mod;
}
LL ans = 0, res;
rep(i, 1, n)
{
res = a[i] * (1LL * (i - 1)*i / 2 + 1LL * (n - i)*(n - i + 1) / 2) % mod;
res += a[i] * min(i, n - i + 1) % mod;
if (i - 1 >= n - i + 1)
{
res += L[n - i + 1] % mod;
res += (l[i - 1] - l[n - i + 1])*(n - i + 1) % mod;
}
else
{
res += L[i - 1] % mod;
}
if (n - i >= i)
{
res += R[i] % mod;
res += (r[n - i] - r[i])*i % mod;
}
else
{
res += R[n - i];
}
ans = (ans * 10 + res) % mod;
}
printf("%lld\n", ans);
}
return 0;
}

标签:1810,Reverse,int,res,CSU,const,mod,include,define
From: https://blog.51cto.com/u_15870896/5838620

相关文章

  • CSU 1809 Parenthesis
    Description1 p2…pnai andpbiParenthesissequenceSisbalancedifandonlyif:Sisempty;orthereexists balanced parenthesi......
  • CSU 1804 有向无环图
    DescriptionBobo有一个n个点,m条边的有向无环图(即对于任意点v,不存在从点v开始、点v结束的路径)。为了方便,点用1,2,…,n编号。设count(x,y)表示点x......
  • CSU 1803 2016
    Description 给出正整数n和m,统计满足以下条件的正整数对(a,b)的数量:1.1≤a≤n,1≤b≤m;2.a×b是2016的倍数。Input......
  • 25. Reverse Nodes in k-Group
     Giventhe head ofalinkedlist,reversethenodesofthelist k atatime,andreturn themodifiedlist.  classSolution{publicListNodere......
  • [2022 祥云杯] Reverse部分赛题复现
    女娲补天:指星期天打了一天的V3,再不学re......
  • C++——STL库——reverse、remove、remove_if
    1.reverse函数使用函数功能:将序列[first,last)的元素在原容器中颠倒重排,包含在algorithm库中reverse没有返回值时间复杂度为O(n)示例1:交换vector容器中元素的顺序vect......
  • 单链表巧用dummy_head删除, 找目标位置的前一个node, Reverse考虑0/1的Corner Case,
    今天连续做了三道题,感觉越来越有感觉,第三题直接行云流水,10minAC目录203.移除链表元素单链表巧用dummy_head删除一开始犯的一个逻辑错误:val的节点可能连续出现......
  • leetcode 25 Reverse Nodes in k-Group
    给一个链表,每k个节点一组进行反转,输出反转后的链表hard难度,但突破点很好找,具体解体思路,看下面代码中每行注释publicclassLC25{publicstaticvoidmain(String[]arg......
  • csu 1554: SG Value 思维题
    ​​http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554​​这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!!先不考虑插入操作,就给定一堆数字,求出不能......
  • 1121 - Reverse the lights 思维题
    ​​http://www.ifrog.cc/acm/problem/1121​​我看到这些翻转的题就怕,可能要练下这些专题。我最怕这类题了。一开始想了下dp,dp[i][0/1]表示完成了前i位,第i位不按/按,的......